DenoDDeno
Powered by
edo999E
Denoβ€’2y agoβ€’
1 reply
edo999

How to use crypto generateKeyPairSync?

I'm trying to make
generateKeyPairSync
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
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
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,
});
const { generateKeyPairSync } = await import("node:crypto");

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


What am I doing wrong?
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

Not implemented: crypto.generateKeyPairSync
netop://ウィビNnetop://ウィビ / help
4y ago
node crypto
HashHHash / help
3y ago
How to create a crypto key to use with JWT from a Github pem file
Romuald QuantinRRomuald Quantin / help
4y ago