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
encrypt/decrypt text
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
encrypt/decrypt text
Last edited by jalz on Sat Apr 09, 2016 1:28 am, edited 1 time in total.
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: encrypt/decrypt text
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: encrypt/decrypt text
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....
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....