在 javascript 上使用 AES-128 位加密时不同
Different when encrypting using AES-128 bit on javascript
我在 PHP 中使用 CBC 方法使用 AES-128 位进行加密,但是当我在 javascript 中尝试时,它们会产生不同的输出
我通过在 php
上调整我的代码在 javascript 上尝试了 crypto-js
php 代码我做了什么:
$secretKey = "someivtextforaes";
$ivKey = 'somesecretkeytxt';
$token = 'BD';
$cipher = "AES-128-CBC";
$ciphertext_raw = openssl_encrypt($token, $cipher, $secretKey, false, $ivKey);
return $ciphertext_raw;
这个输出是:
rtFKwdZt4wzgRsgYG/LbiQ==
我使用 crypto-js 在 javascript 上尝试此方法,这是代码:
let secretKey = "someivtextforaes";
let ivKey = 'somesecretkeytxt';
let token = 'BD';
let cipherData = CryptoJS.AES.encrypt(token, secretKey, { iv: ivKey });
console.log(cipherData.toString())
但他们有不同的输出:
U2FsdGVkX1+QsOS9lM2F2Emq
我希望加密输出相同,有人能弄清楚吗?
对于PHP-code,代码和输出不一致。当前代码 returns 输出 50CqXivvXXTfw276AZ8IjA==
(只有交换密钥和 IV 才能获得发布的输出)。
在 JavaScript-code 中,密钥和 IV 必须作为 WordArray
传递,例如
let secretKey = CryptoJS.enc.Latin1.parse("...");
目前,密钥作为字符串传递,因此被解释为密码,从中生成密钥和 IV(参见 The Cipher Input)。
我在 PHP 中使用 CBC 方法使用 AES-128 位进行加密,但是当我在 javascript 中尝试时,它们会产生不同的输出
我通过在 php
上调整我的代码在 javascript 上尝试了 crypto-jsphp 代码我做了什么:
$secretKey = "someivtextforaes";
$ivKey = 'somesecretkeytxt';
$token = 'BD';
$cipher = "AES-128-CBC";
$ciphertext_raw = openssl_encrypt($token, $cipher, $secretKey, false, $ivKey);
return $ciphertext_raw;
这个输出是: rtFKwdZt4wzgRsgYG/LbiQ==
我使用 crypto-js 在 javascript 上尝试此方法,这是代码:
let secretKey = "someivtextforaes";
let ivKey = 'somesecretkeytxt';
let token = 'BD';
let cipherData = CryptoJS.AES.encrypt(token, secretKey, { iv: ivKey });
console.log(cipherData.toString())
但他们有不同的输出: U2FsdGVkX1+QsOS9lM2F2Emq
我希望加密输出相同,有人能弄清楚吗?
对于PHP-code,代码和输出不一致。当前代码 returns 输出 50CqXivvXXTfw276AZ8IjA==
(只有交换密钥和 IV 才能获得发布的输出)。
在 JavaScript-code 中,密钥和 IV 必须作为 WordArray
传递,例如
let secretKey = CryptoJS.enc.Latin1.parse("...");
目前,密钥作为字符串传递,因此被解释为密码,从中生成密钥和 IV(参见 The Cipher Input)。