nodejs的crypto模块

1. 散列HASH

Hash类对数据进行散列摘要的工具,使用示例:

const crypto = require('crypto');
const hash = crypto.createHash('sha256');

hash.update('123')
console.log(hash.digest('hex'))

 2. 散列消息身份验证码HMAC(Hashed Message Authentication Code)

HMac基本介绍

Hmac类是创建HMAC摘要的工具。

const crypto = require('crypto');
const hmac = crypto.createHmac('sha256','a secret');

hmac.update('some data to hash')
console.log(hmac.digest('hex'))

 3. 加密解密

Cipher类用于加密数据,Decipher类用于解密数据。

AES加密概述

AES加密示例:

const crypto = require('crypto');
const cipher = crypto.createCipher('aes192', 'a password');

let encrypted = cipher.update('some clear text data', 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log(encrypted);

 

转载于:https://www.cnblogs.com/windyWu/p/10251362.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值