Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Encrypt and Decrypt

843810Sep 30 2002 — edited Nov 24 2002
I wrote a simple program to decrypt and encrypt and I am having a problem for decryption. I got en error message "Parameters missing".
Could anyone fix my program please.

Here is part of the program

try
{

byte [] plain_password = "This is a my password".getBytes();

// message to be encrypted and decrypted
String message = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

byte [] plain_message = message.getBytes();

MessageDigest md = MessageDigest.getInstance("SHA");

md.update(plain_password);

// DESKeySpec desKeySpec = new DESKeySpec(md.digest());

SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");

KeySpec ks = new DESKeySpec(md.digest());

SecretKey secretKey = skf.generateSecret(ks);

Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");

cipher.init(Cipher.ENCRYPT_MODE, secretKey);

byte [] enc = cipher.doFinal(plain_message);

cipher.init(Cipher.DECRYPT_MODE, secretKey);

byte [] dec = cipher.doFinal(enc);

System.out.println(dec);

} // end try
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 22 2002
Added on Sep 30 2002
13 comments
499 views