Node.js核心模块-crypto加密

提供了加密功能

引入

const crypto = require('crypto');

crypto.createHash(algorithm[,options])

  • algorithm:算法,字符串。取决于平台上的OpenSSL的版本所支持的算法

创建并返回一个Hash类

Hash类

是一个实用工具,用于创建数据的哈希摘要

hash.update(data[,inputEncoding])

  • data string/Buffer/typedArray/dataview
  • inputEncoding 字符串 字符编码,默认为'utf8'编码

使用给定的data更新哈希的内容,该数据的字符编码在inputEncoding给出。如果data是Buffer、TypedArray或DataView,则inputEncoding会被忽略

hash.digest([encoding])

  • encoding 字符串,返回值的字符编码

计算传入要被哈希(使用hash.update()方法)的所有数据的摘要,如果提供了encoding,则返回字符串,否则返回Buffer

调用此方法后,Hash对象不能再被再次使用,多次调用会导致抛出错误

目前看不懂这里说的什么 ̄へ ̄

原文地址:https://www.cnblogs.com/lianglanlan/p/14081083.html