my dog learned polymorphism*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 41133
    
  45
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 - my free Android networking tools app
 
Consider Paul's rocket mass heater.
 
subject: Decryption inconsistencies on different platforms
 
Similar Threads
Problem in getting decrypted data from MySql Database
Please help : IllegalBlockSizeException
javax.crypto.BadPaddingException: Given final block not properly padded
JCE problem URGENT HELP Needed!!!
Very urgent please help : JCE problem