最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - NodeJS Crypto encryption to front end javascript decryption - Stack Overflow

programmeradmin5浏览0评论

I'm looking for AES256 CBC decryption client side,

in nodeJS I use this function to encrypt:

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;

};

but I can't seem to work with it in any client side library (JSAES.js, SJCL.js, pidcrypt)

my guess is it has something to do with the base64/hex encoding decoding, any pointers?

I'm looking for AES256 CBC decryption client side,

in nodeJS I use this function to encrypt:

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;

};

but I can't seem to work with it in any client side library (JSAES.js, SJCL.js, pidcrypt)

my guess is it has something to do with the base64/hex encoding decoding, any pointers?

Share Improve this question asked Feb 24, 2013 at 18:08 RecycleRobotRecycleRobot 8202 gold badges11 silver badges19 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Please have a look at the CryptoJS project:

Here is an example of AES256 CBC encryption / decryption:

Include:

<script src="http://crypto-js.googlecode./svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode./svn/tags/3.1.2/build/ponents/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));

View the demo at jsFiddle

发布评论

评论列表(0)

  1. 暂无评论