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

[1730 byte] By [asyed01a] at [2007-10-3 0:20:32]
# 1

1) Your source does not compile! Take another look at line

String data = ...

2) The line

System.out.println("Encryption: "+ new String(result));

assumes that under the default encoding system all bytes and byte sequences can be converted to chars. Most of the time this is not the case. If you have to display a String representation then use Base64 or HEX encoding or just one of the Arrays.toString() methods. For example

System.out.println("Encryption: "+ Arrays.toString(result));

sabre150a at 2007-7-14 17:12:02 > top of Java-index,Java Essentials,New To Java...
# 2
http://forums.devshed.com/java-help-9/cryotpgraphy-367572.html
yawmarka at 2007-7-14 17:12:02 > top of Java-index,Java Essentials,New To Java...
# 3
Not to be "that guy" but this certainly isnt "New to Java" but it certainly fulfills the requirements to be posted in the "Cryptography" section.
TuringPesta at 2007-7-14 17:12:02 > top of Java-index,Java Essentials,New To Java...
# 4
I have just been trying to find out what you mean by WRAP_MODE & UNWRAP_MODE". Do you mean javax.crypto.SealedObject? If so then the Javadoc for SealedObject says it all.
sabre150a at 2007-7-14 17:12:02 > top of Java-index,Java Essentials,New To Java...