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