-
Notifications
You must be signed in to change notification settings - Fork 529
Closed
Description
As per discussion in our internal chatroom, I am looking to write some code that uses the chacha20-poly1305 algorithm to encrypt (and later, decrypt) some data.
In both running my worker in local Wrangler as well as Vitest tests using @cloudflare/vitest-pool-workers, I see the following error thrown for code that uses "chacha20-poly1305" as an algorithm for createCipheriv
import nodeCrypto from 'node:crypto'
import { promisify } from 'node:util'
const asyncScrypt = promisify(nodeCrypto.scrypt)
const asyncRandomFill = promisify(nodeCrypto.randomFill)
function encryptData(data: string) {
const password = 'Password used to generate key';
const key = await asyncScrypt(password, 'salt', 24)
const ivNonce = nodeCrypto.randomBytes(24) // Initialization vector.
// Normalize the inputted string as specified by
// nodejs.org/api/crypto.html#using-strings-as-inputs-to-cryptographic-apis
data = data.normalize()
const cipher = nodeCrypto.createCipheriv("chacha20-poly1305", key, ivNonce)
let encrypted = cipher.update(data, 'utf8', 'hex');
encrypted += cipher.final("hex")
return encrypted
} β [ERROR] Error: Unknown or unsupported cipher: chacha20-poly1305
at new Cipheriv (node-internal:crypto_cipher:71:21)
at createCipheriv (node-internal:crypto_cipher:236:12)
at null.<anonymous>
Reactions are currently unavailable