當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Node.js crypto.createDiffieHellmanGroup()用法及代碼示例


crypto.createDiffieHellmanGroup()方法是加密模塊的內置應用程序編程接口,用於創建DiffieHellmanGroup。

用法:

crypto.createDiffieHellmanGroup( name )

參數:此方法接受字符串類型的單個參數名稱。



返回值:它返回DiffieHellmanGroup。

以下示例說明了Node.js中crypto.createDiffieHellmanGroup()方法的使用:

範例1:

// Node.js program to demonstrate the      
// crypto.createDiffieHellmanGroup() 
// method 
  
// Includes crypto module 
const crypto = require('crypto'); 
  
// Defining name 
const name = 'modp1'; 
  
// Creating DiffieHellman group 
var diffHell = crypto.createDiffieHellmanGroup(name); 
  
// Displays keys which are encoded 
console.log(diffHell.generateKeys('hex'));

輸出:

ace9c0ae947385ecd238d02e9e6431a8ceb7fd295c88271ba53e46026116d651898d498ea94980cc35a79e7254f02690a8e4b184cd0a7aecad97f77626741423f3b2f2eeb7b0de9a1fa35e22415ed1aae16860a9910528813dd852af5a36700b

範例2:

// Node.js program to demonstrate the      
// crypto.createDiffieHellmanGroup() 
// method 
  
// Includes crypto module 
const crypto = require('crypto'); 
  
// Defining name by using mod15 
// defined in in RFC 3526 
const name = 'modp15'; 
  
// Creating DiffieHellman group 
var diffHell = crypto.createDiffieHellmanGroup(name); 
  
// Displays keys which are encoded 
console.log(diffHell.generateKeys('base64'));

輸出:

vkznZVRMdtS/3I9+cMfXQygigYhfbvo56xk5i3dYpsEnOFJVpcxzK4JEGChsO1cLHsbIKF1nS0hMuxzvfoMrOh6QyOT3Ptp/cmnGAwmRiKkOhpg6mWDUwMN1bxO+SQSUPAEWaRV8ub2wHb3dCxapGCGovuY+7AbrZO4DmIwYHULG01C3gQtLps74q/absa8orsOBW4Dcz/KNaw3njbBrHXnHOpyWiFYasgBz2YwQien8f9zeiAn1CjEbkfGysYdycqzfqBDuW19rDRDPINt1YJqrR5fpsbVjPJOmUNYKoTtk6VqEEx4y48j+f/z/qEOotjRDKJLAi4y7TmFCCfuetTVTn/b2PVGsKK+/rw2GYQZFOgZh/wYhk2UppKkrfBU2a0uBGU6Oo29N/BqgOU3pTZKCR+IXQdLOGJLYOjUo3VVsQbZi0WS9zt6YFwn3HtffkVYF/71lImA2RxZlrGgsPM7B/AytFqd0bVJ4h5ql0OKf/mvWdE2OPEhTRrpeWe5+

參考: https://nodejs.org/api/crypto.html#crypto_crypto_creatediffiehellmangroup_name




相關用法


注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Node.js | crypto.createDiffieHellmanGroup() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。