Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to export private key in jwk format #26643

Open
contrun opened this issue Oct 30, 2024 · 0 comments · May be fixed by #27325
Open

Unable to export private key in jwk format #26643

contrun opened this issue Oct 30, 2024 · 0 comments · May be fixed by #27325
Assignees
Labels
bug Something isn't working correctly crypto Related to node:crypto or WebCrypto

Comments

@contrun
Copy link

contrun commented Oct 30, 2024

export(options: JwkKeyExportOptions | KeyExportOptions<KeyFormat>) {
if (options && options.format === "jwk") {
notImplemented("jwk private key export not implemented");
}
const {
format,
type,
} = parsePrivateKeyEncoding(options, this.asymmetricKeyType);
if (format === "pem") {
return op_node_export_private_key_pem(this[kHandle], type);
} else {
return Buffer.from(op_node_export_private_key_der(this[kHandle], type));
}
}

jwk private key export is currently not implemented. Running the following code would return an error.

import { generateKeyPairSync } from "node:crypto";

const modulusLength = 4096;

const key = generateKeyPairSync("rsa", {
  modulusLength,
  publicKeyEncoding: {
    format: "jwk",
  },
  privateKeyEncoding: {
    format: "jwk",
  },
});

console.log(key);

deno run test.ts

error: Uncaught (in promise) Error: Not implemented: jwk private key export not implemented
const key = generateKeyPairSync("rsa", {
            ^
    at notImplemented (ext:deno_node/_utils.ts:9:9)
    at PrivateKeyObject.export (ext:deno_node/internal/crypto/keys.ts:450:7)
    at generateKeyPairSync (ext:deno_node/internal/crypto/keygen.ts:74:37)
    at file:///home/e/Workspace/deno/test.ts:5:13

Version: deno 2.0.2 (stable, release, x86_64-unknown-linux-gnu)
v8 12.9.202.13-rusty
typescript 5.6.2

@bartlomieju bartlomieju added bug Something isn't working correctly crypto Related to node:crypto or WebCrypto labels Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly crypto Related to node:crypto or WebCrypto
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants