-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
fix(node): implement createPrivateKey #20981
Changes from all commits
f0a659d
53dd564
174c685
318899b
12125ee
6bfba81
5308d16
0de0aa3
ee3183b
8307862
5e4d4cc
bd614d3
3f44e3d
3128d6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. | ||
import { | ||
createPrivateKey, | ||
createSecretKey, | ||
generateKeyPair, | ||
generateKeyPairSync, | ||
|
@@ -202,3 +203,28 @@ for (const primeLength of [1024, 2048, 4096]) { | |
}, | ||
}); | ||
} | ||
|
||
const rsaPrivateKey = Deno.readTextFileSync( | ||
new URL("../testdata/rsa_private.pem", import.meta.url), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
); | ||
|
||
Deno.test("createPrivateKey rsa", function () { | ||
const key = createPrivateKey(rsaPrivateKey); | ||
assertEquals(key.type, "private"); | ||
assertEquals(key.asymmetricKeyType, "rsa"); | ||
assertEquals(key.asymmetricKeyDetails?.modulusLength, 2048); | ||
assertEquals(key.asymmetricKeyDetails?.publicExponent, 65537n); | ||
}); | ||
|
||
// openssl ecparam -name secp256r1 -genkey -noout -out a.pem | ||
// openssl pkcs8 -topk8 -nocrypt -in a.pem -out b.pem | ||
const ecPrivateKey = Deno.readTextFileSync( | ||
new URL("./ec_private_secp256r1.pem", import.meta.url), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto |
||
); | ||
|
||
Deno.test("createPrivateKey ec", function () { | ||
const key = createPrivateKey(ecPrivateKey); | ||
assertEquals(key.type, "private"); | ||
assertEquals(key.asymmetricKeyType, "ec"); | ||
assertEquals(key.asymmetricKeyDetails?.namedCurve, "p256"); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgbT/dwqGGyRs19qy8 | ||
XPyAZVluvTE9N6hIbyVuFyZobrahRANCAATeWMJqmunAZ6o2lumC79MklBB3Z7ZF | ||
ToryVl8HXevci1d/R+OZ6FjYnoICxw3rMXiKMDtUTAFi2ikL20O4+62M | ||
-----END PRIVATE KEY----- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline, we'll enable more native tests once KeyObject support in sign and verify is added (in a follow up).