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!
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!