java DESede Exception

V

Vietor Liu

Hello!
I'm trying to use 3DES for my Programme,But a problem is coming!

Source Code Segment: ENCRYPT--------------------------------------
byte[] key = new byte[24];
byte[] APSecretB = APSecret.getBytes();
int keylen = APSecretB.length;
if (keylen > 24)
keylen = 24;
System.arraycopy(APSecretB, 0, key, 0, keylen);

SecretKey deskey = new SecretKeySpec(key, "DESede");
Cipher c = Cipher.getInstance("DESede");
c.init(Cipher.ENCRYPT_MODE, deskey);
info = apID + "$"
+ new BASE64Encoder().encode(c.doFinal(info.getBytes()));
--------------------------------------

Source Code Segment: DECRYPT--------------------------------------
byte[] key = new byte[24];
byte[] APSecretB = APSecret.getBytes();
int keylen = APSecretB.length;
if (keylen > 24)
keylen = 24;
System.arraycopy(APSecretB, 0, key, 0, keylen);

SecretKey deskey = new SecretKeySpec(key, "DESede");
Cipher c = Cipher.getInstance("DESede");
c.init(Cipher.DECRYPT_MODE, deskey);

String eInfoD = new String(c.doFinal(src));
--------------------------------------


In JDK1.6

successed

In JDK1.42 error message:

javax.crypto.BadPaddingException: Expected PKCS5 but not encountered
at
net.yiii.security.provider.symm.BlockCipher$PKCS5Padding.doUnPadding(Unknown
Source:36)
at net.yiii.security.provider.symm.BlockCipher.engineDoFinal(Unknown
Source:161)
at net.yiii.security.provider.symm.BlockCipher.engineDoFinal(Unknown
Source:112)
at javax.crypto.Cipher.doFinal(Unknown Source:53)
at javax.crypto.Cipher.doFinal(Unknown Source:38)
...

Any ideas? Thanks!
 
V

Vietor Liu

Hi!

In line 'Cipher.getInstance("DESede");',change "DESede" to
"DESede/ECB/PKCS5Padding" OK!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top