I have a problem to generate encryption in JS, I've the encryption generator in PHP like this :
$secret_key = 'thisIsK3y';
$secret_iv = 'tHis1s1v';
$output = false;
$encrypt_method = "AES-256-CBC";
$key = hash( 'sha256', $secret_key );
$iv = substr( hash( 'sha256', $secret_iv ), 0, 16 );
if( $action == 'e' )
{
$output = base64_encode( openssl_encrypt( $string, $encrypt_method, $key, 0, $iv ) );
}
else if( $action == 'd')
{
$output = openssl_decrypt( base64_decode( $string ), $encrypt_method, $key, 0, $iv );
}
return $output;
then I tried to translanguage to JS on React using CryptoJS :
import sha256 from "crypto-js/sha256";
import Base64 from "crypto-js/enc-base64";
import AES from "crypto-js/aes";
let secret_key = "thisIsK3y";
let secret_iv = "tHis1s1v";
let output = false;
let encrypt_method = "AES-256-CBC";
let key = sha256(secret_key);
let iv = String(sha256(secret_iv)).substr(0, 16);
if (action == "e") { // encrypt action
output = AES.encrypt("test", Utf8.parse(key), {
iv: Utf8.parse(iv),
}).toString();
alert(Base64.parse(output));
}
then the alert show me this encryption : fd0337c029ad25c240316a1d61db9144, then I try to decrypt in my php.but it's show me plain text seems like non-printable ascii
b"}¦7▀À4█ÍØ█ù6ÒM§Ú¡]ÙW[¸^8"
and there is PHP notice :
PHP Notice: iconv(): Detected an illegal character in input string in /var/www/html/blabla/vendor/symfony/var-dumper/Dumper/AbstractDumper.php on line 203
Anyone can help me out ?