edo999E
Denoβ€’2y agoβ€’
1 reply
edo999

How to use crypto generateKeyPairSync?

I'm trying to make generateKeyPairSync work, but it fails.

The sample code at the bottom of https://docs.deno.com/api/node/crypto/~/generateKeyPairSync does not work on deno 1.44.4 (MacOS Sonoma 14.5 M2 chip). I get:
error: Uncaught (in promise) Error: Not implemented: crypto.PrivateKeyObject.prototype.export
const { publicKey, privateKey } = generateKeyPairSync("rsa", {
                                  ^
    at notImplemented (ext:deno_node/_utils.ts:9:9)
    at PrivateKeyObject.export (ext:deno_node/internal/crypto/keys.ts:206:5)
    at generateKeyPairSync (ext:deno_node/internal/crypto/keygen.ts:77:37)
    at file:///deno/test.ts:3:35


I get the same thing with generateKeyPair.

The only way it works, is if I remove the both key encodings from the options:
const { generateKeyPairSync } = await import("node:crypto");

const { publicKey, privateKey } = generateKeyPairSync("rsa", {
  modulusLength: 4096,
});


What am I doing wrong?
Was this page helpful?