Skip to content

πŸ› Bug Report β€” Runtime APIs - Figure out support for chacha20-poly1305Β #4930

@dxh9845

Description

@dxh9845

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>

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions