Answer the question
In order to leave comments, you need to log in
How to do encryption in PHP and decryption in Node JS?
Hello. Faced such a problem, you need to encrypt a string in PHP using the OpenSSL library and the aes-256-cbc method, and decrypt it on the Node JS server ... How many methods I tried did not work ... Tell me how to do it ....
If anything PHP I use this function:
function encode($str, $key)
{
$encryption_key = base64_decode($key);
$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
$encrypted = openssl_encrypt($str, 'aes-256-cbc', $encryption_key, 0, $iv);
return base64_encode($encrypted . '::' . $iv);
}
Answer the question
In order to leave comments, you need to log in
Googled first result: Using AES-256-CBC with OpenSSL, node.js and PHP
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question