• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Decryption inconsistencies on different platforms

 
J. West
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class with a utility method for encrypting / decrypting text. The class is listed as below. The class works great when only on Windows platform, but when it tries to decrypt some text (that was originally encrypted on Windows) on AIX or Mac OS X, I get this exception... Any ideas why the inconsistencies between platforms?

javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.SunJCE_h.b(DashoA6275)
at com.sun.crypto.provider.SunJCE_h.b(DashoA6275)
at com.sun.crypto.provider.DESCipher.engineDoFinal(DashoA6275)
at javax.crypto.Cipher.doFinal(DashoA12275)

The method looks like this...I've changed the byte[] with the key for security purposes...


public static String crypt(String pStrValue,int piCipherMode)throws java.security.NoSuchAlgorithmException,NoSuchPaddingException,java.security.InvalidKeyException,IllegalBlockSizeException,BadPaddingException{
byte[] keyArray = new byte[]{'a','a','a','a','a','a','a','a'};
SecretKey key = new SecretKeySpec(keyArray, "DES");
Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding");
cipher.init(piCipherMode, key);
byte[] input = pStrValue.getBytes();
byte[] output = cipher.doFinal(input);
String pStrNewValue = new String(output);
return pStrNewValue;
}
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things come to mind: this and the fact that byte-endian issues may come into play if you're moving binary data between platforms.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic