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

 

相关文章:

  • 2021-06-01
  • 2022-12-23
  • 2021-11-21
  • 2022-12-23
  • 2021-07-29
  • 2021-05-28
  • 2021-05-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案