Node.js - hash.update() 方法
Hash 类是用于创建数据哈希摘要的众多实用类之一。hash.update() 方法使用传入的数据更新哈希内容,以及与参数一起传入的编码。如果未传入编码且数据为字符串,则使用'utf8' 编码。
语法
hash.update(data, [inputEncoding])
参数
如下所述为参数:
data - 此输入参数获取将更新哈希内容的数据的输入。
InputEncoding - 用于对输入数据或数据字符串进行编码的编码
示例 1
创建一个名为 "hashUpdate.js" 的文件并复制以下代码段。在创建文件后,使用命令 "node hashUpdate.js" 运行此代码
// hash.update() demo Example
// Importing the crypto module
const crypto = require('crypto');
// Creating a hash instance with the below values
var hash = crypto.createHash('sha256')
// Data to update the hash
.update('Welcome to TutorialsPoint !')
// Using digest to get its hex value
.digest('hex');
// Printing the hash value
console.log("Hash Value: " + hash);输出
C:\home
ode>> node hashUpdate.js Hash Value: 5f55ecb1ca233d41dffb6fd9e307d37b9eb4dad472a9e7767e8727132b784461
示例 2
让我们再看一个例子
// hash.update() demo Example
// Importing the crypto module
const crypto = require('crypto');
// Creating a hash instance with the below values
var hash = crypto.createHash('sha256')
// Data to update the hash
.update('Welcome to TutorialsPoint !')
// We can update the hash multiple times
.update('SIMPLY LEARNING')
// Using digest to get its base64 value
.digest('base64');
// Priniting the hash value
console.log("Base64 Value: " + hash);输出
C:\home
ode>> node hashUpdate.js Base64 Value: WdXHoQhqYk4EBEXYBuvmRFGdid+xnxUk22YACiYtnIk=
广告
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP