Draft
Conversation
Contributor
Author
|
FYI I've also tried making specific ASN.1 structures for the various enc/kdf algorithms however I'm not sure if it's worth adding ptoffy/swift-crypto@encrypted-pem...ptoffy:swift-crypto:encrypted-pem-types |
5 tasks
Lukasa
pushed a commit
that referenced
this pull request
Feb 23, 2026
Add support for creating RSA private keys from encrypted PEM files. ### Checklist - [X] I've run tests to see all new and existing tests pass - [X] I've followed the code style of the rest of the project - [X] I've read the [Contribution Guidelines](CONTRIBUTING.md) - [X] I've updated the documentation if necessary #### If you've made changes to `gyb` files - [ ] I've run `./scripts/generate_boilerplate_files_with_gyb.sh` and included updated generated files in a commit of this pull request ### Motivation: Resolves #264 ### Modifications: Adds an initializer to `_RSA.Signing.PrivateKey` that takes the encrypted PEM representation and the encryption password and calls the high-level BoringSSL function to parse the encrypted key format. Tests were copied from #318 by @ptoffy. ### Result: RSA private keys can be created from encrypted PEM files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for creating keys from encrypted PEM files
Checklist
If you've made changes to
gybfiles.script/generate_boilerplate_files_with_gyband included updated generated files in a commit of this pull requestMotivation:
See #264
Modifications:
For now the PR provides encrypted PEM initialisers for RSA using the following encryption algorithms:
PBES2withAES{128, 192, 256}_CBCandhmacWithSHA256PBES2with3DES_CBC(via BoringSSL) andhmacWithSHA256PBES2withAES_GCMPBE_MD5_DES_CBCPBE_MD5_RC2_CBCPBE_SHA1_DES_CBCPBE_SHA1_RC2_CBCScryptPBKDF2withSHA1PBKDF2withSHA512This list is not final and algorithms can be both added and removed.
The aim is to add support for the rest of the keys and as many encryption algorithms as possible (where appropriate), and as the PR evolves I'll update this comment with the current state.
The current strategy is to use SwiftASN1 to parse the provided PEM file and decrypt it depending on which encryption algorithm is found.
The PR still has a long way to got and while this approach works, for now it's mainly still a proof of concept and I'm open to discussing different/better strategies
Result:
Keys can be created from encrypted PEM files