Decrypting AES-128-ECB string with no salt

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
lightman
Posts: 3
Joined: Thu Jul 10, 2014 5:09 am

Decrypting AES-128-ECB string with no salt

Post by lightman » Thu Jul 10, 2014 5:35 am

Hello,

I've just started using LiveCode community edition and am trying to use the encrypt/decrypt commands to store and retrieve passwords locally for a legacy application on another platform.

The scenario is that I have a 32 character alphanumeric string representing the password stored in a text field -
ec16882f9fd3a59077fae786fc46a233, which is 'password' encrypted with 'secret' using AES-128-ECB.

My understanding is that I would use the decrypt command to convert this to plaintext.

I have two fields (tHexValue and tClearText) in the stack and a button with code in the onmouseup event:

decrypt field tHexValue using "aes128" with password "secret"
put it into tClearText

This fails and there's no obvious error.

To troubleshoot, I tried encrypting using the equivalent, but got a string I wasn't expecting.

encrypt field tClearText using "aes128" with password "secret"
put it into tHexValue

Result:
Salted__U¹)T–[Ÿ³%ÁFd"ºo¡©j/µ

My question is how do I convert the output into a 32 character alphanumeric string 'ec16882f9fd3a59077fae786fc46a233'?
I'm also not sure how to handle the lack of a salt value, as the documentation seems to indicate a random salt is used if one isn't specified in the command?
I'm probably missing something really obvious, but would appreciate any pointers or assistance.

Thank you.

Calvin.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Decrypting AES-128-ECB string with no salt

Post by Simon » Thu Jul 10, 2014 6:51 am

Hi Calvin,
Welcome to the forum!:)

ec16882f9fd3a59077fae786fc46a233 looks like an md5 hash not an encrypted password.
As you've seen encryption does this U¹)T–[Ÿ³%ÁFd"ºo¡©j/µ and is the sort of thing I'd expect.
Check out md5 in the Dictionary there is a very useful note at the bottom (if I remember correctly).

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

lightman
Posts: 3
Joined: Thu Jul 10, 2014 5:09 am

Re: Decrypting AES-128-ECB string with no salt

Post by lightman » Thu Jul 10, 2014 7:29 am

Thanks for the welcome and for replying, Simon.

The string does look like an MD5 hash, but is actually the hex representation of the encrypted password.

You can check this here: aes[dot]online-domain-tools[dot]com

Screenshot for confirmation:
domaintools.png
Based on the result, it might also be padded in blocks of 32 characters.

1234567890123456 = 8dcde5eafebe57bd0addef5c90a5fa6a
12345678901234567= 8dcde5eafebe57bd0addef5c90a5fa6adb06daae0c3c9421d098ed2f8f292557

I'm guessing the legacy app has a 16 character limit on passwords, so all the strings stored in the field are 32 characters which is why it looks like a hash.

I suspect what I need to do is somehow convert the U¹)T–[Ÿ³%ÁFd"ºo¡©j/µ to hex?

Once again, thanks for taking the time to reply, and if you have any further insights, I'd be grateful for the input.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Decrypting AES-128-ECB string with no salt

Post by Klaus » Thu Jul 10, 2014 12:37 pm

Hi Calvin,

being no encryption expert, just one caveat:
"encrypt ..." will return BINARY data and putting BINARY data into a TEXT (sic!) FIELD might cause data corruption!
Looks like this does happen here.

Store the data in a custom property and see if that works:
...
## Always use QUOTES around object names (= strings)!
encrypt field "tClearText" using "aes128" with password "secret"
put it into tHexValue
set the cEncryptedData of this stack to tHexValue
...
put the cEncryptedData of this stack to tHexValue
decrypt tHexValue using "aes128" with password "secret"
put it into tClearText
...

Best

Klaus

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Decrypting AES-128-ECB string with no salt

Post by FourthWorld » Thu Jul 10, 2014 2:44 pm

lightman wrote:I suspect what I need to do is somehow convert the U¹)T–[Ÿ³%ÁFd"ºo¡©j/µ to hex?
See the binaryDecode function in the Dictionary, e.g.:

Code: Select all

function CleanHash s
   local tHex
   get binaryDecode("h*", sha1digest(s &"SomeRandomSalt"), tHex)
   return tHex
end CleanHash
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

lightman
Posts: 3
Joined: Thu Jul 10, 2014 5:09 am

Re: Decrypting AES-128-ECB string with no salt

Post by lightman » Thu Jul 10, 2014 9:33 pm

Thank you all for the help. Got a prototype working. :)

Post Reply