Node.js – hash.copy() 方法
哈希 类是用于创建数据散列摘要的诸多实用类之一。hash.copy() 方法创建一个新的哈希对象,其中包含当前哈希对象的内部状态的深层副本。
语法
hash.copy([options])
参数
- 选项 −此输入参数输入用于控制流行为,因此将包含 stream.tranformOptions。
示例 1
创建文件"hashCopy.js"并复制以下代码片段。创建文件后,使用命令"node hashCopy.js"运行此代码。
// hash.update() demo Example
// Importing the crypto module
const crypto = require('crypto');
// Defining the hash
const hash = crypto.createHash('sha256');
// Updating the hash value
hash.update('Welcome to TutorialsPoint');
// Displaying the hash value after copying
console.log("Hash is: " + hash.copy.digest('hex'));输出
C:\home
ode>> node hashCopy.js Hash is: c1e6fe9c48a1cf16fa6928053975cf3d987619ca0992ac20861c32a9fa0d5d17
示例 2
// hash.update() demo Example
// Importing the crypto module
const crypto = require('crypto');
// Defining the hash
const hash = crypto.createHash('sha256');
// Updating the hash value
hash.update('Tutorials Point - SIMPLY LEARNING');
// Creating copies
const copy1 = hash.copy();
const copy2 = hash.copy();
// Displaying the hash value after copying
console.log("Original Hash is: " + hash.digest('hex'));
console.log("Copy1 Hash is: " + copy1.digest('hex'));
console.log("Copy2 Hash is: " + copy2.digest('hex'));输出
C:\home
ode>> node hashCopy.js Original Hash is: 5f7a802a94340899861ac3babd895e9c7fa8240dc8f5cf87144072d456d73a05 Copy1 Hash is: 5f7a802a94340899861ac3babd895e9c7fa8240dc8f5cf87144072d456d73a05 Copy2 Hash is: 5f7a802a94340899861ac3babd895e9c7fa8240dc8f5cf87144072d456d73a05
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP