NodeJS加密加密到前端javascript解密 [英] NodeJS Crypto encryption to front end javascript decryption

查看:1115
本文介绍了NodeJS加密加密到前端javascript解密的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找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);
返回加密;

};

但我似乎无法在任何客户端库(JSAES.js,SJCL我的猜测是与base64 / hex编码解码有关,任何指针?

解决方案

请查看 CryptoJS 项目:



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



包含:

 < script src =http://crypto-js.googlecode.com/svn/tags/ 3.1.2 /建造/汇总/ aes.js>< /脚本> 
< 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 decryptpted = CryptoJS.AES.decrypt(encrypted,passPhrase,{mode:CryptoJS.mode.CFB});

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

查看演示 jsFiddle


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?

解决方案

Please have a look at the CryptoJS project:

Here is an example of AES256 CBC encryption / decryption:

Include:

<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));

View the demo at jsFiddle

这篇关于NodeJS加密加密到前端javascript解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆