Node.js 中的 crypto.createSign() 方法
crypto.createSign() 將建立和返回一個 sign 物件,該物件使用引數中傳遞的演算法。你可以使用 crypto.getHashes() 獲取所有可用的摘要演算法的名稱。你可以使用簽名演算法的名稱(例如“RHA-SHA256”)建立 Sign 例項,僅在某些情況下,而不是摘要演算法。
語法
crypto.createSign(algorithm, [options])
引數
上述引數的描述如下 −
algorithm – 它輸入建立 sign 物件/例項時要使用的演算法名稱。
options – 這是一個可選引數,可用於控制流的行為。
示例
建立一個名為 createSign.js 的檔案並複製以下程式碼段。建立檔案後,使用以下命令執行此程式碼,如以下示例所示 −
node createSign.js
createSign.js
// Node.js program to demonstrate the use of createSign() method
// Importing the crypto module
const crypto = require('crypto');
// Creating sign object with the input algorithm
const sign = crypto.createSign('SHA256');
// Returning the sign object
console.log(sign);輸出
C:\home
ode>> node createSign.js Sign { _handle: {}, _writableState: WritableState { objectMode: false, highWaterMark: 16384, finalCalled: false, needDrain: false, ending: false, ended: false, finished: false, destroyed: false, decodeStrings: true, defaultEncoding: 'utf8', length: 0, writing: false, corked: 0, sync: true, bufferProcessing: false, onwrite: [Function: bound onwrite], writecb: null, writelen: 0, bufferedRequest: null, lastBufferedRequest: null, pendingcb: 0, prefinished: false, errorEmitted: false, emitClose: true, autoDestroy: false, bufferedRequestCount: 0, corkedRequestsFree: { next: null, entry: null, finish: [Function: bound onCorkedFinish] } }, writable: true, _events: [Object: null prototype] {}, _eventsCount: 0, _maxListeners: undefined }
示例
我們再看一個例子。
// Node.js program to demonstrate the use of createSign() method
// Importing the crypto module
const crypto = require('crypto');
// Creating sign object with the input algorithm
const sign = crypto.createSign('SHA256');
// Returning the sign object
console.log(sign.write('Welcome to Tutorials Point'));輸出
C:\home
ode>> node createSign.js true
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP