我有一个简单的NodeJS程序用于加密明文:
var crypto = require("crypto");
var compatEnc = crypto.createCipher("aes-256-cbc", "password");
compatCrypted = compatEnc.update("Message", "utf8", "hex");
compatCrypted += compatEnc.final("hex");
console.log(compatCrypted);
// 0293cf0bdf5323cff809ba406ffc8283
我尝试在浏览器中解密0293cf0bdf5323cff809ba406ffc8283。
<!doctype html>
<html>
<body>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/core-min.js"></script>
<script>
var nosalt = CryptoJS.lib.WordArray.random(0);
// { salt : null } will generate random salt
var enc = CryptoJS.AES.decrypt("0293cf0bdf5323cff809ba406ffc8283", "password",
{ salt: nosalt });
console.log(CryptoJS.enc.Utf8.stringify(enc));
</script>
</body>
</html>
输出为空白。你能告诉我我的解密代码有什么问题吗?谢谢。