aspose file tools*
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
Author

Decryption inconsistencies on different platforms

J. West
Greenhorn

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

Joined: Mar 22, 2005
Posts: 39549
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Decryption inconsistencies on different platforms
 
Similar Threads
Please help : IllegalBlockSizeException
Very urgent please help : JCE problem
javax.crypto.BadPaddingException: Given final block not properly padded
Problem in getting decrypted data from MySql Database
JCE problem URGENT HELP Needed!!!