Hi, I’d like to decrypt, on my OpenFL app a string encryped on PHP. At the server, I’m using “openssl_encrypt” like this:
$encrypted = openssl_encrypt($original, ‘AES-128-CTR’, $encKey, 0, $encVec);
At my OpenFL project, I’m using the Haxe Crypto library (GitHub - HaxeFoundation/crypto: Cross platform cryptographic functions for Haxe), following their AES decryption example:
var aes:Aes = new Aes();
var key = Bytes.ofString(encKey);
var iv:Bytes = Bytes.ofString(encVec);
var data = Bytes.ofString(‘my encrypted string from php’);
trace(aes.decrypt(Mode.CTR, data, Padding.NoPadding));
This, however, does not work. Does anyone here use this Crypto library to tell me how to handle this?
Never tried the library, but have you tried to encrypt and decrypt with the library only to see if it works properly?
Also, you can compare encrypted string from PHP and haxe library.
The most probably your problem is about
iv and using
Bytes.ofString and not
Bytes.ofString could have a problem to convert some characters to correct representation in Bytes .
For that reason is more reliable to use
The other thing is to check
encVec in hex code.
Probably they are different.
Also , you set option = 0 for padding in
openssl_encrypt , but no padding option ( OPENSSL_ZERO_PADDING ) is 2 . ( check here : PHP: Other Constants - Manual )
From PHP Doc:
Without using OPENSSL_ZERO_PADDING, you will automatically get PKCS#7 padding.
Maybe you want to use padding in your Haxe code ? In that case set
Thank you! I believe the problem wasn’t on “ofString” - the results were the same when using hex versions of the key/iv (I believe I wasn’t using any problematic char), but the padding was indeed messing up with the decodig. Thank you a lot!