Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class main1{
- public static void main1(String[] args) {
- System.out.println("Before");
- try{
- KeyGenerator keygenerator = KeyGenerator.getInstance("DES");
- SecretKey myDesKey = keygenerator.generateKey();
- Cipher desCipher;
- desCipher = Cipher.getInstance("DES");
- byte[] text = "No body can see me.".getBytes("UTF8");
- desCipher.init(Cipher.ENCRYPT_MODE, myDesKey);
- byte[] textEncrypted = desCipher.doFinal(text);
- String s = new String(textEncrypted);
- System.out.println(s);
- desCipher.init(Cipher.DECRYPT_MODE, myDesKey);
- byte[] textDecrypted = desCipher.doFinal(textEncrypted);
- s = new String(textDecrypted);
- System.out.println(s);
- }catch(Exception e)
- {
- System.out.println("Exception");
- }
- System.out.println("After");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement