S
S
s2sk13372017-06-01 06:04:34
PHP
s2sk1337, 2017-06-01 06:04:34

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

1 answer(s)
S
Sergey Sokolov, 2017-06-01
@sergiks

Googled first result: Using AES-256-CBC with OpenSSL, node.js and PHP

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question