Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBacterius

Posted 24 September 2012 - 10:07 PM

Don't use Strings to store binary data (raw encrypted data is binary) or reencode them somehow (hex, base64). Your raw encrypted string may or may not contain special characters which completely mess up the Java string encoding and handling, so you don't get what you expect out of getBytes(). This causes the padding data to turn out wrong, causing the error you're seeing. Try using byte arrays all the way between encryption and decryption and see if it works then.

Also, ECB is insecure, so only use it for learning. Secondly, if you want to avoid the whole padding issue in the future, use a mode of operation which does not require padding but instead an initialization vector, such as CTR or CFB!

#1Bacterius

Posted 24 September 2012 - 10:07 PM

Don't use Strings to store binary data (raw encrypted data is binary) or reencode them somehow (hex, base64). Your raw encrypted string may or may not contain special characters which completely mess up the Java string encoding and handling, so you don't get what you expect out of getBytes(). This causes the padding data to turn out wrong, causing the error you're seeing. Try using bytes array all the way between encryption and decryption and see if it works then.

Also, ECB is insecure, so only use it for learning. Secondly, if you want to avoid the whole padding issue in the future, use a mode of operation which does not require padding but instead an initialization vector, such as CTR or CFB!

PARTNERS