New crypto capabilities in Node.js - UUID's and Primes
July 29, 2021
Much has been happening in the Node.js crypto subsystem lately. I introduced the Web Cryptography API implementation, and added the new support for the HKDF key derivation scheme previously. Here I discuss two powerful new capabilities for generating random UUIDs and random prime numbers. Read more: https://www.nearform.com/blog/new-crypto-capabilities-in-node-js/
randomuuid.js
import { randomUUID } from 'crypto';
console.log(randomUUID());
generateprime.js
const prime = crypto.generatePrimeSync(32);
console.log(prime);
// Or asynchronous ...
crypto.generatePrime(32, { safe: true, add: 2n, rem : 1n, bigint: true }, (err, prime) => {
console.log(prime);
})