KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > lightcrypto > test > Run


1 package net.sourceforge.lightcrypto.test;
2
3 import net.sourceforge.lightcrypto.*;
4
5 import java.io.ByteArrayOutputStream JavaDoc;
6 import java.io.DataOutputStream JavaDoc;
7 import java.io.ByteArrayInputStream JavaDoc;
8
9 import org.bouncycastle.util.encoders.Base64;
10
11 /**
12  * Created by IntelliJ IDEA.
13  * User: u997879
14  * Date: Aug 28, 2003
15  * Time: 9:38:00 AM
16  * To change this template use Options | File Templates.
17  */

18 public class Run {
19       public static void main(String JavaDoc args[]) {
20          try {
21
22
23
24              System.out.println("ciphertext:" + PBECrypt.decrypt(new StringBuffer JavaDoc("DW5WQMZuGkfKEg80QqDRrG1kOZ9gI/Pd"),new StringBuffer JavaDoc("mypassword")));
25
26
27              System.out.println("plain:" + PBECrypt.encrypt(new StringBuffer JavaDoc("this is A test"),new StringBuffer JavaDoc("mypassword")));
28
29              /*Key k = new Key();
30
31              //Key.generatekey("c:/temp/tempkey.key",new StringBuffer("mypassword"));
32
33
34              SafeObject sf = k.loadkey("c:/temp/AES_128.key",new StringBuffer("mypassword"));
35
36              StringBuffer plaintext = Crypt.decrypt(new StringBuffer("MxXSSQireZV7BEl2FyTMzsY9dQz9GvtHdhRkmmNMl2M="), sf);
37
38              System.out.println("ciphertext:" + plaintext);
39
40
41
42
43         /*ByteArrayOutputStream bao = new ByteArrayOutputStream();
44         DataOutputStream dao = new DataOutputStream(bao);
45
46         // encrypt text
47         Stream.encrypt(new ByteArrayInputStream("blabla".getBytes()), dao, sf, 8);
48
49         StringBuffer result = new StringBuffer(new String(Base64.encode(bao.toByteArray())));
50
51         System.out.println("cipher: " + result);
52
53
54
55         // close outputstream
56         dao.flush();
57         dao.close();
58
59         bao = new ByteArrayOutputStream();
60         dao = new DataOutputStream(bao);
61
62         // decrypt
63         Stream.decrypt(new ByteArrayInputStream(Base64.decode(result.toString())), dao, sf, 8);
64
65         System.out.println("decipher: " + new String(bao.toByteArray()));
66
67         //close outputstream
68         dao.flush();
69         dao.close();
70
71
72
73              //System.out.println(HMacs.mac(new StringBuffer("mytext")));
74
75
76              //Key k = new Key();
77              //Key.generatekey("c:/temp/tempkey.key",new StringBuffer("mypassword"));
78
79
80
81
82              //System.out.println("Load key...");
83              //SafeObject sf = k.loadkey("c:/temp/tempkey.key",new StringBuffer("mypassword"));
84
85
86              //System.gc();
87
88              //Thread.currentThread().sleep(5 * 1000);
89
90              //System.out.println(sf.getBase64());
91
92              //StringBuffer cipher = PBECrypt.encrypt(new StringBuffer("The Bouncy Castle Crypto package is a Java implementation of cryptographic algorithms"),new StringBuffer("mypassword"));
93
94              //StringBuffer plaintext = Crypt.decrypt(new StringBuffer("7SDEw/aYBsZ0FnVyi+JbKGGS22kwPO+LBESAb1DPHdE="), sf);
95
96              //System.out.println("ciphertext:" + cipher);
97
98              //StringBuffer plain = PBECrypt.decrypt(cipher,new StringBuffer("mypassword"));
99
100                //System.out.println("plain:" + plain);
101
102              //Thread.currentThread().sleep(30 * 1000);
103
104              //sf.clearText();
105              //sf = null;
106
107              //System.gc();
108
109
110              //sf.clearText();
111
112              //Thread.currentThread().sleep(5 * 1000);
113
114
115              /*System.out.println("key:" + sf.getBase64());
116
117              StringBuffer m = Macs.mac(new StringBuffer("mytext"),sf);
118
119              System.out.println("mac:" + m);
120
121               System.out.println("mac equals?:" + Macs.macEquals(new StringBuffer("mytext"), m,sf));
122
123              // encrypt
124              /*StringBuffer ciphertext = Crypt.encrypt(new StringBuffer("mytest"), sf);
125              System.out.println("cipher: " + ciphertext);
126
127              StringBuffer plaintext = Crypt.decrypt(ciphertext,sf);
128              System.out.println("plaintext: " + plaintext); */

129
130              /*
131
132              SafeObject sf = k.loadkey("c:/temp/tempkey.key",new StringBuffer("password"));
133
134              System.out.println("key:" + sf.getBase64());
135
136               System.out.println("key2:" + Hsqldb.loadkey("c:/temp/tempkey.key",new StringBuffer("password")));
137                                    */

138
139             //System.out.println(Crypt.Digesters(new StringBuffer("mytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytext"),"SHA512"));
140
//System.out.println(Digesters.digest("mytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytextmytext","SHA512"));
141

142             //System.out.println(Crypt.Digesters(new FileInputStream("c:/javabooks/j-jstl0415.pdf"),null));
143

144             //Key.generatekey("c:/temp/test1.key",new StringBuffer("mypassword"), new StringBuffer("sdkdffddiejjdjd"));
145

146             //String sqlkey = Hsqldb.loadkey("c:/temp/test1.key",new StringBuffer("mypassword"));
147

148             //String cipher = Hsqldb.encrypt("mytest",sqlkey);
149

150             //System.out.println(cipher);
151

152             //String decipher = Hsqldb.decrypt(cipher,sqlkey);
153

154             //System.out.println(decipher);
155

156             //Key.generatekey("c:/temp/tempkey.key",new StringBuffer("mypassword"));
157

158             //SafeObject k = new SafeObject();
159
//k = Key.loadkey("c:/temp/AES_128.key",new StringBuffer("mypassword"));
160

161             //System.out.println(k.getBase64());
162

163             // encrypt
164
//StringBuffer ciphertext = Crypt.encrypt(new StringBuffer("test"),k);
165
//System.out.println("cipher: " + ciphertext);
166

167             //SafeObject k2 = new SafeObject();
168
//k2 = Key.loadkey("c:/temp/test1.key",new StringBuffer("mypassword"));
169

170
171             //StringBuffer plaintext = Crypt.decrypt(ciphertext,k);
172
//System.out.println("plaintext: " + plaintext);
173

174              /*// encrypt file
175              Crypt.encryptFile("c:/javabooks/jstl3.pdf", "c:/javabooks/jstl3.encrypted", k);
176
177               // decrypt file
178              Crypt.decryptFile("c:/javabooks/jstl3.encrypted", "c:/javabooks/jstl3.decrypted.pdf", k);
179              */

180
181              //System.out.println(Digesters.digestFromFile("c:/javabooks/jstl3.pdf",null));
182
//System.out.println(Digesters.digest(new StringBuffer("balbal"),"SHA512"));
183

184          } catch (Exception JavaDoc ex) {
185             ex.printStackTrace();
186             System.out.println(ex.getMessage());
187          }
188      }
189 }
190
Popular Tags