node.js md5加盐加密

nodejs qmt 77℃

const crypto = require("crypto");
const password = '123456';

// 加密
var salt = crypto.randomBytes(16).toString("hex");
var hash = crypto
  .pbkdf2Sync(password, salt, 1000, 64, `sha512`)
  .toString(`hex`);

console.log(hash);

crypto.randomBytes(3).toString("hex") 生成的字符串长度是 6。
这是因为 crypto.randomBytes(3) 生成了一个包含 3 个字节的随机字节数组,
然后 .toString("hex") 将其转换为十六进制表示的字符串。

由于每次的salt值都是任意的,随意上面的代码是不可逆的。

每个字节转换为十六进制表示需要两个字符,所以 3 个字节需要 6 个字符来表示。

如果是发现加密的字符里面,字母不超过字母f, 大概率是用的十六进制生成的随机字节,然后再转为字符串。

转载请注明:QMT|Ptrade量化交易 » node.js md5加盐加密

喜欢 (0)