1import javax.crypto.Cipher;
2import javax.crypto.KeyGenerator;
3import javax.crypto.SecretKey;
4
5public class HelloWorld{
6 public static void main(String[] args) {
7
8 try{
9 KeyGenerator keygenerator = KeyGenerator.getInstance("DES");
10 SecretKey myDesKey = keygenerator.generateKey();
11
12 Cipher desCipher;
13 desCipher = Cipher.getInstance("DES");
14
15
16 byte[] text = "No body can see me.".getBytes("UTF8");
17
18
19 desCipher.init(Cipher.ENCRYPT_MODE, myDesKey);
20 byte[] textEncrypted = desCipher.doFinal(text);
21
22 String s = new String(textEncrypted);
23 System.out.println(s);
24
25 desCipher.init(Cipher.DECRYPT_MODE, myDesKey);
26 byte[] textDecrypted = desCipher.doFinal(textEncrypted);
27
28 s = new String(textDecrypted);
29 System.out.println(s);
30 }catch(Exception e)
31 {
32 System.out.println("Exception");
33 }
34 }
35}
36