Tag: php openssl

PHP中使用OpenSSL进行AESencryption/在Node.js中解密

我正在使用PHP和Nodejs与OpenSSL进行对称encryption。 PHP使用OpenSSL库,Node.js解密基于实现的encryption。 问题是Node.js中的解密文本只是部分正确的 。 PHP函数进行encryption function encrypt($text, $pw, $base64 = true) { $method = 'aes-256-cbc'; $iv_len = openssl_cipher_iv_length($method); $iv = openssl_random_pseudo_bytes($iv_len); $pw = substr(md5($pw),0,32); $cipher = openssl_encrypt ($text ,$method ,$pw ,!$base64 ,$iv ); if($base64) { $pw = base64_encode($pw); $iv = base64_encode($iv); } return array( 'iv' => $iv, 'pw' => $pw, 'text' => $text, 'cipher' => […]