encrypt/decrypt text

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
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

encrypt/decrypt text

Post by jalz » Sat Apr 09, 2016 1:14 am

Hey Guys,
Been doing a lot of reading on the subject and getting my head in a twist. I've wrote the following two functions which encrypt and decrypt text that will go into a database or be retrieved and displayed from a database. I'm experimenting with the AES cipher as I understand not all ciphers in LC work on each platform. I also understand that when I encrypt text, it returns a binary value which could get corrupted when inserted in my database. I therefore need to encode to a hex value and store this. Logic suggests that to retrieve the value back form the database I just need to do the reverse what I did to encrypt to decrypt the hash or are the functions I've written below a one way hash only?

If I'm using H* as the formatsList to binary decode to hex, should I be using B* to binary encode back to binary?

Many thanks
Jalz


function encrypt_text tData
encrypt tData using "aes-128-cbc" with key "FFFFFFFFFFFFDDCC" at 128 bit
get binarydecode("H*",it,eData)
return eData
end encrypt_text

function decrypt_text tData
put binaryencode("B*",tData) into eData
decrypt eData using "aes-128-cbc" with key "FFFFFFFFFFFFDDCC" at 128 bit
return eData
end decrypt_text
Last edited by jalz on Sat Apr 09, 2016 1:28 am, edited 1 time in total.

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

Re: encrypt/decrypt text

Post by FourthWorld » Sat Apr 09, 2016 1:21 am

You may find using base64encode and base64decode more convenient and producing smaller output.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: encrypt/decrypt text

Post by jalz » Sat Apr 09, 2016 1:48 am

Thanks Richard,
I've got it working, by simply changing the binary encode format to H*, the same as the decode function.
Still dont get it though, probably need some sleep to think about it but if I'm decoding binary to hex, thought I would have to encode hex back to binary....

Post Reply