• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

Decryption inconsistencies on different platforms

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;
Posts: 43016
  • 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.
    Bookmark Topic Watch Topic
  • New Topic