Anybody know Encryption/Decryption
Hay guys
I am working on Cryptography with java. In a question I have to do Encryption and decryption on a file using DES with FOUR modes. These modes are ENCRYPTION_MODE, DECRYPTION_MODE, WRAP_MODE & UNWRAP_MODE.
I did ENCRYPTION_MODE & DECRYPTION_MODE but I don抰 know how to do WRAP_MODE & UNWRAP_MODE . Can anybody show me how to do it?
Here is my piece of code
import javax.crypto.*;
import java.security.*;
public class DESCryptpTest {
public static void main(String[] args) {
Security.addProvider(new com.sun.crypto.provider.SunJCE());
try
{
KeyGenerator kg = KeyGenerator.getInstance("DES");
Key key = kg.generateKey();
Cipher cipher = Cipher.getInstance("DES");
String source = "The Java Cryptography Extension (JCE) "+
supplies a uniform way for applications to use encryption and "+
digital signatures in Java."The encryption classes (in the packages "+
java.security and javax.crypto) provide a convenient way to "+perform encryption and digital signing. Methods are also "+
available within the classesto support the storage and retrieval "+
of keys. ";
byte [] data = source.getBytes();
System.out.println("Original data: "+ new String(data));
cipher.init(Cipher.ENCRYPT_MODE ,key);
byte [] result = cipher.doFinal(data);
System.out.println("Encryption: "+ new String(result));
cipher.init(Cipher.DECRYPT_MODE,key );
byte [] origianl = cipher.doFinal(result);
System.out.print("Decryption: "+ new String(origianl));
}
catch (Exception e){
e.printStackTrace();
}
}
}
Thanks a lot in advance

