从crypto和php生成的aes-128 cbc代码是不同的

我的node.js代码如下所示:

const testTempToken = (req, res) => { const temp_token = req.body.temp_token; const key_val = req.body.key_val; const temp_token_utf8_md5 = crypto.createHash('md5').update(utf8.encode(temp_token)).digest("bianry") const key = temp_token_utf8_md5; const iv = temp_token_utf8_md5; const cipher = crypto.createCipheriv('aes-128-cbc', key, iv); const to_be_encrypted = utf8.encode(key_val); const encrypted = cipher.update(to_be_encrypted, 'utf8', 'base64'); res.json({ status: '200', data: encrypted }); }; 

我的php代码如下所示:

 <?php namespace App\Http\Controllers; use Illuminate\Http\Request; class CardTransaction extends Controller { //this is the function that takes the parameter from API public function store(Request $request) { $tempToken = $request->token; $keyValuePair = $request->keyVal; // $encryptedString = $request->encryptedString; /* The code given below is for encryption */ $protectPayAPI = new ProtectPayApi(); $encryptedString = $protectPayAPI->setUtf8EncodeMd5HashTempToken($tempToken) ->encryptString(utf8_encode($keyValuePair)) ->getEncryptedString(); return response() ->json(['output' => base64_encode($encryptedString)]); } } class ProtectPayApi { /* for temp tokens */ private $_tempToken; /* md5 hash of utf8 encoded temp token */ private $_md5HashUtf8TempToken; private $_encryptedString; private $_decryptedString; /** * @param string $tempToken * @return $this */ public function setUtf8EncodeMd5HashTempToken($tempToken) { $this->_tempToken = $tempToken; $this->_md5HashUtf8TempToken = md5(utf8_encode($tempToken),TRUE); return $this; } /** * Encrypts the string using the set $this->_md5HashUtf8TempToken * @param string $stringToEncrypt * @return $this */ public function encryptString($stringToEncrypt) { $this->_encryptedString = openssl_encrypt( $stringToEncrypt, 'AES-128-CBC', $this->_md5HashUtf8TempToken, OPENSSL_RAW_DATA, $this->_md5HashUtf8TempToken ); return $this; } /** * Decrypts the string using the set $this->_md5HashUtf8TempToken * @param string $stringToDecrypt * @return $this */ public function decryptString($stringToDecrypt) { $this->_encryptedString = $stringToDecrypt; $this->_decryptedString = openssl_decrypt( $stringToDecrypt, 'AES-128-CBC', $this->_md5HashUtf8TempToken, OPENSSL_RAW_DATA, $this->_md5HashUtf8TempToken ); return $this; } /** * @return mixed */ public function getEncryptedString() { return $this->_encryptedString; } /** * @return mixed */ public function getDecryptedString() { return $this->_decryptedString; } } 

为两者inputtemp_token(node)/token(php)

0e359993-7ac0-4ce4-b00a-7a3644a38ca6a8e3706d-42cd-491e-90eb-97b6e2ac7b9b

inputkey_val(node)/KeyVal(php)都是

的authToken = 0e359993-7ac0-4ce4-b00a-7a3644a38ca6a8e3706d-42cd-491e-90eb-97b6e2ac7b9b&PayerID = 1675506249460924&金额= 10.00&货币代码= USD&ProcessMethod =捕捉&PaymentMethodStorageOption =无&InvoiceNumber = Invoice123&注释1 =注释1&注释2 =注释2&回声= EchoTest中&RETURNURL = http://kraftdigital.in/&ProfileId=2148409&PaymentProcessType = CreditCard&StandardEntryClassCode = &DisplayMessage = True&Protected = False

Now cipher string generated in node is

7zGK8dxx1L / fhE6EDQW3klMl6Lt0A5ca0a9dTHjz8zIacExuiLkgy49v6H39oNbUSVcRdqJ9SoWZ3oqS0qZGPVsvbGwziK6 / fnxD9vvl66afR1cUL0DswS8pfIbV8ngFQGjG2q9lcnnxeiGFzzFP6GTxhkH1CIZpbepGS + BTCbkbWCc93voYVz0g6 + apclALewr0qo1tHe4rKtIYijEwePGq4uJjSlVqp / hlVJrFmbBCCM9O7i4 + oYnb / C33MB / kBGVRe34ACyiecTc + MAsXJFSPDA9mtJei4z9qGjklLuUZqdofBvKA0LsxiQ5y2y3ARdA44M5YbMfgwqvRKvqFifMykm7Ldre68ZWCsHSc44zF99 + SnbIzzXP30f80wWHu7r66svsw + 5LXx /智商+ VkY0vJCHOJBBM8bbGWX7ehOY / 7mkQSiYY0YoKfOjZBhNizpypeU3tItee5lxY2Hwh6jf2pm0eaeUGTc7Iqz2dg25tno0eVsJLi + xjKHZKQR1tbPJN74ImVbxNCiKyHaQUd

cipher string generated in PHP is

7zGK8dxx1L / fhE6EDQW3klMl6Lt0A5ca0a9dTHjz8zIacExuiLkgy49v6H39oNbUSVcRdqJ9SoWZ3oqS0qZGPVsvbGwziK6 / fnxD9vvl66afR1cUL0DswS8pfIbV8ngFQGjG2q9lcnnxeiGFzzFP6GTxhkH1CIZpbepGS + BTCbkbWCc93voYVz0g6 + apclALewr0qo1tHe4rKtIYijEwePGq4uJjSlVqp / hlVJrFmbBCCM9O7i4 + oYnb / C33MB / kBGVRe34ACyiecTc + MAsXJFSPDA9mtJei4z9qGjklLuUZqdofBvKA0LsxiQ5y2y3ARdA44M5YbMfgwqvRKvqFifMykm7Ldre68ZWCsHSc44zF99 + SnbIzzXP30f80wWHu7r66svsw + 5LXx /智商+ VkY0vJCHOJBBM8bbGWX7ehOY / 7mkQSiYY0YoKfOjZBhNizpypeU3tItee5lxY2Hwh6jf2pm0eaeUGTc7Iqz2dg25tno0eVsJLi + xjKHZKQR1tbPJN74ImVbxNCiKyHaQUdZSC78Qr2LrTYJeJpZB1C02c =

在我的node.js代码中是否有任何缺失。 因为php密码string是正确和validation的。