🌐
Node.js
nodejs.org › api › crypto.html
Crypto | Node.js v25.8.1 Documentation
The node:crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
🌐
W3Schools
w3schools.com › nodejs › nodejs_crypto.asp
Node.js Crypto Module
Built-in Modules EventEmitter (events) Worker (cluster) Cipher (crypto) Decipher (crypto) DiffieHellman (crypto) ECDH (crypto) Hash (crypto) Hmac (crypto) Sign (crypto) Verify (crypto) Socket (dgram, net, tls) ReadStream (fs, stream) WriteStream (fs, stream) Server (http, https, net, tls) Agent (http, https) Request (http) Response (http) Message (http) Interface (readline)
🌐
npm
npmjs.com › package › crypto-js
crypto-js - npm
October 1, 2023 - JavaScript library of crypto standards.. Latest version: 4.2.0, last published: 2 years ago. Start using crypto-js in your project by running `npm i crypto-js`. There are 15240 other projects in the npm registry using crypto-js.
      » npm install crypto-js
    
Published   Oct 24, 2023
Version   4.2.0
Author   Evan Vosberg
🌐
Medium
medium.com › @tony.infisical › guide-to-nodes-crypto-module-for-encryption-decryption-65c077176980
Guide to Node’s crypto module for encryption/decryption | by Tony | Medium
October 1, 2023 - Guide to Node’s crypto module for encryption/decryption Encryption operations can be tricky, so much that paid encryption-as-a-service companies exist just to ensure that cryptographic operations …
🌐
Node.js
nodejs.org › api › webcrypto.html
Web Crypto API | Node.js v25.8.1 Documentation
March 30, 2019 - const { subtle } = globalThis.crypto; (async function() { const key = await subtle.generateKey({ name: 'HMAC', hash: 'SHA-256', length: 256, }, true, ['sign', 'verify']); const enc = new TextEncoder(); const message = enc.encode('I love cupcakes'); const digest = await subtle.sign({ name: 'HMAC', }, key, message); })(); copy
🌐
LogRocket
blog.logrocket.com › home › node.js crypto module: a tutorial
Node.js crypto module: A tutorial - LogRocket Blog
June 4, 2024 - With cryptography in Node.js, you can hash passwords and store them in the database so that data cannot be converted to plain text after it is hashed; it can only be verified. When malicious actors get ahold of your database, they cannot decode ...
🌐
GeeksforGeeks
geeksforgeeks.org › node.js › what-is-crypto-module-in-node-js-and-how-it-is-used
What is Crypto Module in Node.js and How it is used ? - GeeksforGeeks
June 14, 2024 - The crypto module in Node.js provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions. This module enables you to perform various security operations, such as ...
🌐
Node.js
nodejs.org › download › rc › v8.12.0-rc.2 › docs › api › crypto.html
Crypto | Node.js v8.12.0-rc.2 Documentation
3 weeks ago - The crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
🌐
CoreUI
coreui.io › answers › how-to-use-crypto-module-in-nodejs
How to use crypto module in Node.js · CoreUI
June 4, 2024 - Learn how to use the crypto module in Node.js for hashing, encryption, and cryptographic operations in secure applications.
Find elsewhere
🌐
Pabbly
pabbly.com › home › tutorials › nodejs › crypto in node.js
Crypto In Node.js
June 14, 2024 - Crypto is a module in Node.js which deals with an algorithm that performs data encryption and decryption.
🌐
TatvaSoft
tatvasoft.com › home › nodejs cryptography: encrypt and decrypt data
Nodejs Cryptography: Encrypt and Decrypt Data
November 14, 2025 - The inbuilt library known as crypto comes with NodeJS, and it can be used to encrypt and decrypt the data. It contains various crypto algorithms for the same, making it suitable for any type of data.
🌐
Readthedocs
node.readthedocs.io › en › latest › api › crypto
Crypto - node - Read the Docs
Note: createCipher derives keys with the OpenSSL function EVP_BytesToKey with the digest algorithm set to MD5, one iteration, and no salt. The lack of salt allows dictionary attacks as the same password always creates the same key. The low iteration count and non-cryptographically secure hash ...
🌐
Metaschool
metaschool.so › home › blockchain › understanding node.js crypto module
Understanding Node.js Crypto Module
March 29, 2024 - The crypto model is part of the core libraries of Nodejs and doesn’t require any external dependencies. It provides developers with functions to perform cryptographic operations.
🌐
Yonatan's dev blog
blog.yonatan.dev › cryptography-with-node-crypto-module
Mastering Cryptography Fundamentals with Node’s crypto module
March 28, 2025 - This post covers the fundamentals of Cryptography and shows how to put them to use with Node.js' crypto module.
🌐
Deno
docs.deno.com › api › node › crypto
crypto - Node documentation
July 12, 2025 - The node:crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
🌐
Artoon Solutions
artoonsolutions.com › home › understanding nodejs crypto for better security
Nodejs crypto module: A Step-By-Step Tutorial
April 29, 2025 - These capabilities are crucial ... The Nodejs crypto module is a built-in library that provides a set of cryptographic functionalities to help developers secure their applications....
🌐
Fireship
fireship.io › lessons › node-crypto-examples
Tutorial: Cryptography Concepts for Node.js Developers | Fireship.io
The following tutorial explains essential cryptography concepts and implements them with the builtin Node.js crypto module.
Published   February 20, 2025
🌐
Cloudflare
developers.cloudflare.com › directory › workers › runtime apis › node.js compatibility › crypto
crypto · Cloudflare Workers docs
October 24, 2024 - The node:crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
Top answer
1 of 1
5

How do you combine the IV with the encrypted data? Or do you not need to do this? Some tutorials I've seen combine the IV with the encrypted data while others do not

When decrypting, the IV of the encryption must be used, which is why the IV must be passed to the decrypting side. Since the IV is not secret, it is usually concatenated with the ciphertext.
Note that a static IV that is known to both sides is not a solution, as this results in reuse of key-IV pairs for fixed keys, which is a vulnerability. To avoid this, a random IV is often used (as it is already done in the posted code).

Am I using base64 correctly? I'm not sure if I'm passing base64 as a parameter at the right time or not

When encrypting, it is most convenient to concatenate IV, the result of the update()-call and the final()-call as Buffer and to convert this into a Base64url string using the specifier base64url. The decryption must be implemented accordingly.

Sample:

import crypto from 'node:crypto';

var key = Buffer.from('MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTIzNDU2Nzg5MDE=', 'base64');

function encrypt(plaintext) {
  const iv = crypto.randomBytes(16);
  const cipher = crypto.createCipheriv(
    'aes-256-cbc',
    key,
    iv
  );
  let encrypted = Buffer.concat([iv, cipher.update(plaintext, 'utf8'), cipher.final()]);
  return encrypted.toString('base64url');
}

function decrypt(ivCiphertextB64) {
  const ivCiphertext = Buffer.from(ivCiphertextB64, 'base64url');
  const iv = ivCiphertext.subarray(0, 16);
  const ciphertext = ivCiphertext.subarray(16);
  const cipher = crypto.createDecipheriv(
    'aes-256-cbc',
    key,
    iv
  );
  let decrypted = Buffer.concat([cipher.update(ciphertext), cipher.final()]);
  return decrypted.toString('utf-8');
}

var ct = encrypt('The quick brown fox jumps over the lazy dog');
var dt = decrypt(ct);
console.log(ct);
console.log(dt);