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.

Thanks
ronayersAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

thanks for your help.
0
_agx_Commented:
Definitely don't trim() the value. With encryption, everything is significant. Even white space.  

#Decrypt(field, "myencryptionkey","DESEDE")#
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

ronayersAuthor Commented:
ok, removed TRIM() and it still bombed.
0
_agx_Commented:
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.
0
_agx_Commented:
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.

<cfoutput>
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>
</cfloop>
</cfoutput>
0
_agx_Commented:
That is about all I can suggest without seeing some real values and code ..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.