Decrypt from php is not working

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: Klaus, FourthWorld, heatherlaine, kevinmiller

Post Reply
jabedbd
Posts: 8
Joined: Wed Sep 04, 2019 12:40 pm

Decrypt from php is not working

Post by jabedbd »

How can decrypt a string from php encrypted using live code?
for example

Code: Select all

encrypt pTokenText using "aes-128-cbc" with key tKeyHex and IV tIVHex at 128 bit
then trying using php to decrypt the data from server using

Code: Select all

$decrypted = openssl_decrypt($encrypted,'aes-128-cbc',$encryption_key, 0,$iv);
but it's not working.

I have checked other example found on the forum they are using mcrypt_encrypt function of php which is deprecated from php 7 .2 version. Anyone have any working example of it?
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Decrypt from php is not working

Post by Klaus »

Hi jabedbd,

welcome to the forum!
A little "Hello" or something would not have hurt for the very first posting. 8)

How do you save the encrypted data to file in LC? "encrypt" returns BINARY data
so you will need to use -> "binfile:..." when saving from LC.

Best

Klaus
jabedbd
Posts: 8
Joined: Wed Sep 04, 2019 12:40 pm

Re: Decrypt from php is not working

Post by jabedbd »

Klaus wrote: Wed Sep 04, 2019 2:11 pm ow do you save the encrypted data to file in LC? "encrypt" returns BINARY data
so you will need to use -> "binfile:..." when saving from LC.
Hey Klaus, thanks for your quick reply.

basically what i did. after encrypting the the string using the base64Encode function i have encoded the output to base64 encoded string. then i post the data to the php server.
where first i decode the string from base64 then try to decrypt to get the original string. but it's not working.
Klaus
Posts: 14325
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Decrypt from php is not working

Post by Klaus »

OK, that was just a quick guess, sorry no brilliant idea in the moment...
bwmilby
Posts: 464
Joined: Wed Jun 07, 2017 5:37 am
Contact:

Re: Decrypt from php is not working

Post by bwmilby »

Check out https://github.com/bwmilby/lc-community ... r/AES_Demo
I’m not sure if it has everything you need, but worth a look.
mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3582
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Decrypt from php is not working

Post by mwieder »

Try making the cipher uppercase. Seems like it matters.
In addition, if you check "the result" after the encryption you'll see what went wrong:
Using lowercase gives "invalid cipher name", and the "it" variable is then empty.

Code: Select all

encrypt pTokenText using "AES-128-CBC" with key tKeyHex and IV tIVHex at 128 bit
if the result is empty then
  put base64encode(it) into tTextToPost
else
  answer the result
end if
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: Decrypt from php is not working

Post by sphere »

after encrypting the the string using the base64Encode function i have encoded the output to base64 encoded string. then i post the data to the php server.
base64Encode is not encrypting
reading your line of text it looks like you base64Encoded it twice...
Try this: Encrypt-->base64Encode-->URLencode-->send to server

then read from server: base64Decode-->decrypt-->plain text/data
ludis
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3
Joined: Thu Nov 05, 2009 11:01 pm
Contact:

Re: Decrypt from php is not working

Post by ludis »

PHP base64 encodes the result, so you have to base 64 decode the response before decrypting it.
Post Reply