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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
