Search This Blog

2023/04/21

Crypto Module in Node.js

 crypto module in Node.js is native module,It provides cryptographic functionality

such as hash functions, encryption and decryption algorithms, digital signatures,
and more.

Some of the features provided by the crypto module include:

Hash functions: the module provides a range of hash functions such as
SHA-256, SHA-512, and MD5.
Encryption and decryption: the module provides algorithms for symmetric
encryption and decryption such as AES,
as well as asymmetric encryption and decryption such as RSA.
Digital signatures: the module provides functionality for generating
and verifying digital signatures
using algorithms such as RSA, DSA, and ECDSA.

crypto module in Node.js depends on OpenSSL, which is a widely used open
source library that provides cryptographic functions such as encryption,
decryption, and digital signature generation and verification.

OpenSSL is a third-party library that is not maintained by the Node.js project.

Example sha256

const crypto = require('crypto');
const data = 'Hello, world!';

// Create a hash object
const hash = crypto.createHash('sha256');

// Update the hash object with the data to be hashed
hash.update(data);

// Generate the hash as a hex string
const hashResult = hash.digest('hex');

console.log(`Hash of "${data}": ${hashResult}`);

output:
Hash of "Hello, world!": 315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3



No comments:

Post a Comment