Node.js crypto.setFips() Function
Last Updated :
23 Apr, 2021
The crypto.setFips() method is an inbuilt application programming interface of class Crypto within the crypto module which is used to enable the FIPS compliant crypto provider in a FIPS-enabled Node.js build.
Syntax:
const crypto.setFips(bool)
Parameters: This API takes the Boolean value as a parameter.
Return Value: This API does not return anything.
Example 1:
index.js
const crypto = require( 'crypto' )
try {
const val = crypto.setFips( true );
console.log( "FIPS compliant crypto"
+ " provider has been enabled" )
} catch (e) {
console.log( "FIPS mode is not available." );
}
|
Run the index.js file using the following command:
node index.js
Output:
FIPS mode is not available.
Example 2:
index.js
const crypto = require( 'crypto' )
try {
const val = crypto.setFips( false );
console.log( "FIPS compliant crypto "
+ "provider has been disabled" );
} catch (e) {
console.log( "ERR_CRYPTO_FIPS_UNAVAILABLE" )
}
|
Output:
ERR_CRYPTO_FIPS_UNAVAILABLE
Reference: https://nodejs.org/dist/latest-v15.x/docs/api/crypto.html#crypto_crypto_setfips_bool
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...