Error "Given final block not properly padded" when decrypting string

I am getting this weird error when i decrypt certain types of strings. I am encrypting strings using DESEDE in CF8. When i decrypt text like pjpeiry1 it will bomb with "Given final block not properly padded". this also seems to be true with text like pjpeiry11 and pjpeiry22. Really need some help on this one.

Who is Participating?
_agx_Connect With a Mentor Commented:
Definitely don't trim() the value. With encryption, everything is significant. Even white space.  

#Decrypt(field, "myencryptionkey","DESEDE")#
You mean it bombs when you decrypt in CF8? Can you provide the code snippets you're using.
ronayersAuthor Commented:
Correct. It bombs when decrypting. Coldfusion encrypts everything without error. just bombs when i decrupt certian strings.
bombs on this line

thanks for your help.
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

ronayersAuthor Commented:
ok, removed TRIM() and it still bombed.
Since you say it doesn't occur every time, can you provide sample values we can test  (both encrypt and decrypt)? Because this type of error is usually caused by a code problem.
Also, how is the encrypted value handled in between the encrypt() and decrypt()? ie Is it being stored in a db (cookie, etc...) then transferred to another page and decrypted.  A lot of times, the encrypted value gets unintentionally corrupted somewhere in the process (white space is lost, etc..). So decrypt() fails because the final encrypted string used is not the same as it was. Obviously everything used to decrypt (the string, key, etc..) has to be exactly the same as it was, or it will fail.

One way to check this is to perform a char-by-char comparison of the encrypted string, right after the encrypt() and right before the decrypt().  If the results aren't the same, that explains the error. So you just need to find out where the value is getting corrupted.

Encrypted String Length = #len(encryptedString)#<hr>
<cfloop from="1" to="#len(encryptedString)#" index="x">
      <cfset c = mid(encryptedString, x, 1)>
      [#x#] =  #c# ( ASCII #asc(c)# ) <br>
That is about all I can suggest without seeing some real values and code ..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.