lyL
Denoβ€’3y agoβ€’
9 replies
ly

bad resource id with node:crypto

function test() {
  const key = randomBytes(32);
  const iv = randomBytes(16);
  const cipher = createCipheriv("aes-256-cbc", key, iv);
  const decipher = createDecipheriv("aes-256-cbc", key, iv);
  const data = "Hello World";
  const encrypted =
    cipher.update(data, "utf8", "base64") + cipher.final("base64");
  const decrypted =
    decipher.update(encrypted, "base64", "utf8") + decipher.final("utf8");
  console.dir({ data, encrypted, decrypted });
}

test();

error: Uncaught BadResource: Bad resource ID
    cipher.update(data, "utf8", "base64") + cipher.final("base64");
                                                   ^
    at Cipheriv.final (ext:deno_node/internal/crypto/cipher.ts:35:13)
Was this page helpful?