crypto.createSign()方法用於創建使用所述算法的Sign對象。此外,您可以使用crypto.getHashes()方法訪問所有可用摘要算法的名稱。
用法:
crypto.createSign( algorithm, options )
參數:該方法接受上述和以下所述的兩個參數:
- algorithm:它是一個字符串類型值。可以通過應用簽名算法(例如“ RSA-SHA256”)的名稱來代替摘要算法來創建Sign實例。
 - options:它是一個可選參數,用於控製流的行為。它返回一個對象。
 
返回值:它返回Sign對象。
以下示例說明了Node.js中crypto.createSign()方法的使用:
範例1:
// Node.js program to demonstrate the  
// crypto.createSign() method 
  
// Including crypto module 
const crypto = require('crypto'); 
  
// Defining the algorithm to be used 
const algo = 'RSA-SHA256'; 
  
// Creating Sign object 
const sign = crypto.createSign(algo); 
  
// Output 
console.log(sign);輸出:
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,
  domain:null,
  _events:[Object:null prototype] {},
  _eventsCount:0,
  _maxListeners:undefined }
範例2:
// Node.js program to demonstrate the  
// crypto.createSign() method 
  
// Including crypto module 
const crypto = require('crypto'); 
  
// Defining the algorithm to be used 
const algo = 'SHA256'; 
  
// Creating Sign object 
const sign = crypto.createSign(algo); 
  
// Prints true 
sign.write('some data to sign');輸出:
true
參考: https://nodejs.org/api/crypto.html#crypto_crypto_createsign_algorithm_options
相關用法
- Node.js GM whitePoint()用法及代碼示例
 - Node.js GM sharpen()用法及代碼示例
 - Node.js GM threshold()用法及代碼示例
 - Node.js GM thumbnail()用法及代碼示例
 - Node.js GM transparent()用法及代碼示例
 - Node.js GM resize()用法及代碼示例
 - Node.js GM drawPolyline()用法及代碼示例
 - Node.js GM charcoal()用法及代碼示例
 - Node.js GM drawRectangle()用法及代碼示例
 - Node.js GM drawPolygon()用法及代碼示例
 
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Node.js | crypto.createSign() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
