crypto.setFips()方法是加密模塊內的類Crypto的內置應用程序編程接口,用於在FIPS-enabled Node.js構建中啟用符合FIPS的加密提供程序。
用法:
const crypto.setFips(bool)
參數:該API將布爾值作為參數。
返回值:此API不返回任何內容。
範例1:
index.js
// Node.js program to demonstrate the  
// crypto.setFips() method
  
// Importing crypto module
const crypto = require('crypto')
  
// Checking for error
try {
  
    // Enabling the FIPS compliant 
    // crypto provider by using
    // setFips() method
    const val = crypto.setFips(true);
  
    // Display the result
    console.log("FIPS compliant crypto"
        + " provider has been enabled")
  
} catch (e) {
      
    // Display error if any
    console.log("FIPS mode is not available.");
}使用以下命令運行index.js文件:
node index.js
輸出:
FIPS mode is not available.
範例2:
index.js
// Node.js program to demonstrate the  
// crypto.setFips() method
  
// Importing crypto module
const crypto = require('crypto')
  
// Enabling the FIPS compliant 
// crypto provider by using
// setFips() method
try {
  
    // Function call
    const val = crypto.setFips(false);
  
    // Display the result
    console.log("FIPS compliant crypto "
        + "provider has been disabled");
} catch (e) {
    console.log("ERR_CRYPTO_FIPS_UNAVAILABLE")
}輸出:
ERR_CRYPTO_FIPS_UNAVAILABLE
參考: https://nodejs.org/dist/latest-v15.x/docs/api/crypto.html#crypto_crypto_setfips_bool
相關用法
- 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()用法及代碼示例
 - Node.js GM write()用法及代碼示例
 - Node.js GM minify()用法及代碼示例
 - Node.js GM modulate()用法及代碼示例
 
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Node.js crypto.setFips() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
