Page 1 of 1
Decrypt from php is not working
Posted: Wed Sep 04, 2019 12:57 pm
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?
Re: Decrypt from php is not working
Posted: Wed Sep 04, 2019 2:11 pm
by Klaus
Hi jabedbd,
welcome to the forum!
A little "Hello" or something would not have hurt for the very first posting.
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
Re: Decrypt from php is not working
Posted: Wed Sep 04, 2019 3:06 pm
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.
Re: Decrypt from php is not working
Posted: Wed Sep 04, 2019 3:25 pm
by Klaus
OK, that was just a quick guess, sorry no brilliant idea in the moment...
Re: Decrypt from php is not working
Posted: Thu Sep 05, 2019 1:54 pm
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.
Re: Decrypt from php is not working
Posted: Thu Sep 05, 2019 11:59 pm
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
Re: Decrypt from php is not working
Posted: Tue Oct 08, 2019 10:36 am
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
Re: Decrypt from php is not working
Posted: Thu Jul 30, 2020 11:14 am
by ludis
PHP base64 encodes the result, so you have to base 64 decode the response before decrypting it.