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

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

Decrypt from php is not working

Post by jabedbd » Wed Sep 04, 2019 12:57 pm

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: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Decrypt from php is not working

Post by Klaus » Wed Sep 04, 2019 2:11 pm

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 » Wed Sep 04, 2019 3:06 pm

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: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Decrypt from php is not working

Post by Klaus » Wed Sep 04, 2019 3:25 pm

OK, that was just a quick guess, sorry no brilliant idea in the moment...

bwmilby
Posts: 438
Joined: Wed Jun 07, 2017 5:37 am
Location: Henrico, VA
Contact:

Re: Decrypt from php is not working

Post by bwmilby » Thu Sep 05, 2019 1:54 pm

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.
Brian Milby

Script Tracker https://github.com/bwmilby/scriptTracker

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Decrypt from php is not working

Post by mwieder » Thu Sep 05, 2019 11:59 pm

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
Location: Earth, Except when i Jump

Re: Decrypt from php is not working

Post by sphere » Tue Oct 08, 2019 10:36 am

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
Location: Utrecht, Netherlands
Contact:

Re: Decrypt from php is not working

Post by ludis » Thu Jul 30, 2020 11:14 am

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”