-
Notifications
You must be signed in to change notification settings - Fork 197
Add a PKCS#8 DER property to private keys #372
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
Conversation
Motivation: PKCS#8 is pretty widely used. Currently getting a key in PKCS#8 DER representations requires goining through a PKCS8 PEM document and then get its DER bytes. Modifications: Add a computed property to RSA private keys that calls into BoringSSL or Security.framework to get the PKCS8 DER representation of the key. ECDH keys use the existing derRepresentation property to provide a property of the same name. A small ASN1 encoder adds the functionality to ed25519/x25519 keys. Result: The representation can be accessed directly.
|
|
||
| @available(iOS 14.0, macOS 11.0, watchOS 7.0, tvOS 14.0, *) | ||
| extension P521.Signing.PrivateKey { | ||
| public var pkcs8DERRepresentation: Data { |
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.
Do you mind adding doc comments to all of these?
| // Identifies the key agreement algorithm X25519. | ||
| // | ||
| // This identifier is defined in RFC 8410 | ||
| public static let idX25519: ASN1ObjectIdentifier = [1, 3, 101, 110] |
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.
Let's not make these public, we don't need to.
| self.backing.pemRepresentation | ||
| } | ||
|
|
||
| public var pkcs8DERRepresentation: Data { |
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.
Let's add documentation to this as well.
Co-authored-by: Cory Benfield <lukasa@apple.com>
Lukasa
left a comment
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.
Very nice, thanks @josephnoir! ✨
Motivation
PKCS#8 is pretty widely used. Currently getting a key in PKCS#8 DER representations requires going through a PKCS8 PEM document and then get its DER bytes.
Modifications
Add a computed property to RSA private keys that calls into BoringSSL or Security.framework to get the PKCS8 DER representation of the key.
ECDH keys use the existing
derRepresentationproperty to provide a property of the same name.A small ASN1 encoder adds the functionality to ed25519/x25519 keys.
Result
The representation can be accessed directly.
The identifiers for MLKEM are still a draft. As such MLKEM is not included in the PR.