NodeJS加密加密到前端javascript解密

时间:2013-02-24 18:08:46

标签: javascript node.js encryption

我正在寻找AES256 CBC解密客户端,

nodeJS中的

我使用此函数加密:

exports.encrypt = function(txt, cryptkey){
  var cipher = crypto.createCipher('aes-256-cbc',cryptkey);
  var crypted = cipher.update(txt,'utf8','hex');
  crypted += cipher.final('hex');

  console.log(crypted);
  return crypted;

};

但我似乎无法在任何客户端库中使用它(JSAES.js,SJCL.js,pidcrypt)

我的猜测是它与base64 / hex编码解码,任何指针有什么关系?

1 个答案:

答案 0 :(得分:5)

请查看CryptoJS项目:

以下是AES256 CBC加密/解密的示例:

包含:

<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/mode-cfb-min.js"></script>

<强> JS:

var passPhrase = "Secret Phassphrase";

var encrypted = CryptoJS.AES.encrypt("Message", passPhrase, { mode: CryptoJS.mode.CFB });
var decrypted = CryptoJS.AES.decrypt(encrypted, passPhrase, { mode: CryptoJS.mode.CFB });

console.log('encrypted', encrypted);
console.log('decrypted', decrypted.toString(CryptoJS.enc.Utf8));

jsFiddle

查看演示