DenoDDeno
Powered by
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();
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)
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)
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,944Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Bad resource ID ERROR
nekodendislikeNnekodendislike / help
14mo ago
Abusing prototype CryptoKey in `node:crypto`
abiAabi / help
3y ago
node crypto
HashHHash / help
3y ago
Why Bad resource ID occurs?
jeieaJjeiea / help
3y ago