J
jimgardener
i am learning cryptography using Jason weiss book.i tried out
encryption using PBEWithMD5AndDES ,i could encrypt a string as below
byte[] salt=new byte[] { (byte)0x3a, (byte)0x44, (byte)0x7f,
(byte)0xfl,(byte)0xa2, (byte)0xe5, (byte)0x87, (byte)0x31 };
int iter=1000;
String msg="a plain message";
char[] passwd=new char[]{'m','y','c','o','d','e'};
PBEKeySpec pbeKeySpec = new PBEKeySpec(passwd, salt, iter) ;
SecretKeyFactory factory=null;
SecretKey key=null;
Cipher cipher=null;
try{
factory =SecretKeyFactory.getInstance("PBEWithMD5AndDES");
key = factory.generateSecret(pbeKeySpec) ;
cipher=Cipher.getInstance("PBEWithMD5AndDES");
cipher.init (Cipher. ENCRYPT_MODE, key) ;
byte[] cipherText = cipher.doFinal(msg .getBytes()) ;
FileOutputStream out=new FileOutputStream("pbeencrypted.txt");
out.write(cipherText);
Arrays.fill(passwd, '\u0000');
now how can i decrypt this?can i use the same keyspec as above and
what algorithm should i use to create cipher? cipher.init (Cipher.
DECRYPT_MODE, key) ; will cause 'InvalidKeyException: requires PBE
parameters'
can someone help?
jim
encryption using PBEWithMD5AndDES ,i could encrypt a string as below
byte[] salt=new byte[] { (byte)0x3a, (byte)0x44, (byte)0x7f,
(byte)0xfl,(byte)0xa2, (byte)0xe5, (byte)0x87, (byte)0x31 };
int iter=1000;
String msg="a plain message";
char[] passwd=new char[]{'m','y','c','o','d','e'};
PBEKeySpec pbeKeySpec = new PBEKeySpec(passwd, salt, iter) ;
SecretKeyFactory factory=null;
SecretKey key=null;
Cipher cipher=null;
try{
factory =SecretKeyFactory.getInstance("PBEWithMD5AndDES");
key = factory.generateSecret(pbeKeySpec) ;
cipher=Cipher.getInstance("PBEWithMD5AndDES");
cipher.init (Cipher. ENCRYPT_MODE, key) ;
byte[] cipherText = cipher.doFinal(msg .getBytes()) ;
FileOutputStream out=new FileOutputStream("pbeencrypted.txt");
out.write(cipherText);
Arrays.fill(passwd, '\u0000');
now how can i decrypt this?can i use the same keyspec as above and
what algorithm should i use to create cipher? cipher.init (Cipher.
DECRYPT_MODE, key) ; will cause 'InvalidKeyException: requires PBE
parameters'
can someone help?
jim