File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Security and the fly likes Decryption inconsistencies on different platforms Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Security
Bookmark "Decryption inconsistencies on different platforms" Watch "Decryption inconsistencies on different platforms" New topic

Decryption inconsistencies on different platforms

J. West

Joined: Feb 23, 2006
Posts: 1
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,NoSuchPaddingException,,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

Joined: Mar 22, 2005
Posts: 42965
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.
I agree. Here's the link:
subject: Decryption inconsistencies on different platforms
It's not a secret anymore!