node加密
var crypto = require('crypto');
//md5加密
exports.md5 = function (str) {
var md5sum = crypto.createHash('md5');
md5sum.update(str);
str = md5sum.digest('hex');
return str;
}
//aes192加密
exports.encrypt = function (str, secret) {
var cipher = crypto.createCipher('aes192', secret);
var enc = cipher.update(str, 'utf8', 'hex');
enc += cipher.final('hex');
return enc;
}
//aes192解密
exports.decrypt = function (str, secret) {
var decipher = crypto.createDecipher('aes192', secret);
var dec = decipher.update(str, 'hex', 'utf8');
dec += decipher.final('utf8');
return dec;
}
//aes-128-cbc加密和解密
let str = 'aaaaaaaa';
const crypto = require('crypto');
let key = "08281690909";
let iv = "0828164343434";
let encipher = crypto.createCipheriv('aes-128-cbc', key, iv);
let encoded = encipher.update(str,'utf8','hex');
encoded += encipher.final('hex')
console.log('加密'+encoded);//da4941c6e797895527305b6b6ca28b37
let decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
let decoded = decipher.update(encoded,'hex','utf8')
decoded += decipher.final('utf8')
console.log('解密'+decoded)
//aes-128-cbc
exports.wxPaValidate = function(sessionKey, encryptedData, iv) {
const sessionKeyVal = new Buffer(sessionKey, 'base64')
const encryptedDataVal = new Buffer(encryptedData, 'base64')
const ivVal = new Buffer(iv, 'base64')
try {
// 解密
var decipher = crypto.createDecipheriv('aes-128-cbc', sessionKeyVal, ivVal)
// 设置自动 padding 为 true,删除填充补位
decipher.setAutoPadding(true)
var decoded = decipher.update(encryptedDataVal, 'binary', 'utf8')
decoded += decipher.final('utf8')
decoded = JSON.parse(decoded)
} catch (err) {
throw new Error('Illegal Buffer')
}
if (decoded.watermark.appid !== appId) {
throw new Error('Illegal Buffer')
}
return decoded
}
node加密的更多相关文章
- node 加密音频文件 和 解密音频文件
fs.readFile('./downsuccess/'+name+'', {flag: 'r+', encoding: ''}, function (err, data) { c ...
- node加密解密 crytpo
var crypto = require('crypto'); exports.encrypt = function (str, secret) { var cipher = crypto.creat ...
- node-rsa加密,java解密调试
用NODE RSA JS 加密解密正常,用JAVA RSAUtils工具类加密解密正常.但是用node加密玩的java解密不了.原因:node默认的是 DEFAULT_ENCRYPTION_SCHEM ...
- nodejs常用npm包
express常用npm包整理如下 art-template 一款js模板引擎,性能不错 jayson 一款纯node的rpc应用包,可实现rpc服务.tcp.http等服务 multer ...
- babeljs源码
babel.min.js!function(e,t){"object"==typeof exports&&"object"==typeof mo ...
- node.js下使用RSA加密事例(windows)
1.安装openss 直接下载window下的安装包 http://houjixin.blog.163.com/blog/static/3562841020144143494875/ 以我发博文现在的 ...
- [Node.js] 对称加密、公钥加密和RSA
原文地址:http://www.moye.me/2015/06/14/cryptography_rsa/ 引子 对于加解密,我一直处于一种知其然不知其所以然的状态,项目核心部分并不倚重加解密算法时,可 ...
- 夺命雷公狗---node.js---15之加密
node其实也给我们留下了密码的加密发送,不过一般都是用cmd5加密其实也是够了,但是sha1加密也要提下: /** * Created by leigood on 2016/8/31. */ var ...
- Node 实现 AES 加密,结果输出为“byte”。
Node 实现 AES 加密,结果输出为"byte". 最近做个需求,对接一个平台的接口,该平台采用 AES (Advanced Encryption Standard)加密算法, ...
随机推荐
- shell 脚本加密
日常编写shell脚本时会写一些账号和密码写入脚本内,但是不希望泄露账号密码,所以对shell脚本进行加密变成可执行文件. 主要使用 shc 对 Linux shell 脚本加密,shc是一个专业的加 ...
- delete web server(nginx)
#!/bin/bash conf_dir1="/usr/local/nginx/conf/vhost.d" #conf_dir2="/usr/local/apache2/ ...
- AI-视图组件-五个接口的最终简化版
五个接口最终版 #url.py # 序列化最贱版本 url(r'^customer/$', views.CustomerView.as_view({"get":"list ...
- 插件使用一进度条---nprogress
nprogress 是像youtube一样在顶部出现进度条,用在一些加载比较缓慢的场景中. 官方网站是 http://ricostacruz.com/nprogress/ 源码在 https://gi ...
- Php7有哪些新特性:
PHP7在PHP5的基础上又做了一次质的提升,当然改变很多,我这里以我的总结简单说下,主要发生了下面这些更改: 移除了一些旧的特性 ZEND引擎升级到Zend Engine 3,也就是所谓的PHP N ...
- 封装cuda/cudnn写卷积网络前向计算程序
目录 基本编译配置 一些常识 BN层的坑 cuda基础 向cuda核函数传入结构体指针? 参考:http://galoisplusplus.coding.me/blog/2018/05/22/cuda ...
- 【Android】Android WebView 网页输入框获取焦点
webView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEv ...
- http账户密码的截取
首先,http的前提也是基于arp欺骗的,当arp欺骗成功后,方可进行. 具体步骤如下: 1.打开终端,先进行流量的转发:echo 1 >/proc/sys/net/ipv4/ip_forw ...
- pythonclass,day1-day2.
由于是小白,真的一点点的基础都没有,所以压力确实有点大的.全程都是在碰壁,没有明白的地方,装个软件都问题层出不穷,别人几秒钟搞定的,我需要几十分钟,甚至更久...真的是,太强烈的挫败感了,整个人被乌云 ...
- html-背景图片
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...