crypto.hkdf()是加密模塊內的Crypto類的內置應用程序編程接口,用於派生特定長度的 key 。
用法:
const crypto.hkdf(digest, key, salt, info, keylen, callback)
參數:此函數采用以下參數作為參數。
- digest:這是一串摘要算法。
- key:這是秘密的鑰匙
- salt:它代表著重要的價值。
- info:它包含更多信息。
- keylen:它是要生成的 key 的長度。
- callback:這是用於進一步的操作。
返回值:此函數返回特定長度的派生 key 。
範例1:
index.js
// Node.js program to demonstrate the
// crypto.hkdf() function
// Importing crypto module
const crypto = require('crypto')
// getting dervied key
// by using hkdf() method
const val = crypto.hkdf('sha512', 'key', 'salt',
'info', 64, (err, derivedKey) => {
// checking if any error is found
if (err) throw err;
// display the result
console.log(Buffer.from(derivedKey).toString('hex'));
});
使用以下命令運行index.js文件。
node index.js
輸出:
24156e2c35525baaf3d0fbb92b734c8032a110a3f12e25 96e441e1924870d84c3a500652a723738024432451046fd237e fad8392fb686c5277a59e0105391653
範例2:
index.js
// Node.js program to demonstrate the
// crypto.hkdf() function
// Importing crypto module
const crypto = require('crypto')
// creating and intializing array buffer
const key = new ArrayBuffer(8);
// getting dervied key
// by using hkdf() method
const val = crypto.hkdf('sha512', key, 'salt',
'info', 32, (err, derivedKey) => {
// checking if any error is found
if (err) throw err;
// display the result
console.log(Buffer.from(derivedKey).toString('hex'));
});
使用以下命令運行index.js文件。
node index.js
輸出:
bb105ac3235f285bd53b68cb95bf78c7fe5f3 a7924ac64d291f68ba2bd0430e1
相關用法
- Node.js GM charcoal()用法及代碼示例
- Node.js GM blur()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
- Node.js GM drawLine()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
- Node.js GM drawCircle()用法及代碼示例
- Node.js GM drawEllipse()用法及代碼示例
- Node.js GM drawPolygon()用法及代碼示例
- Node.js GM drawRectangle()用法及代碼示例
- Node.js GM paint()用法及代碼示例
- Node.js GM orderedDither()用法及代碼示例
- Node.js GM roll()用法及代碼示例
- Node.js GM segment()用法及代碼示例
- Node.js GM quality()用法及代碼示例
- Node.js GM raise()用法及代碼示例
- Node.js GM resize()用法及代碼示例
- Node.js GM transparent()用法及代碼示例
- Node.js GM thumbnail()用法及代碼示例
- Node.js GM threshold()用法及代碼示例
- Node.js GM whitePoint()用法及代碼示例
- Node.js GM whiteThreshold()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Node.js scrypto.hkdf() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。