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

Added RSAKey.makeKeyPair() and RSAKey.pemString #44

Merged
merged 2 commits into from
Apr 1, 2019
Merged

Conversation

Andrew-Lees11
Copy link
Contributor

Description

This pull request adds a new function to CryptorRSA:

public class func makeKeyPair(_ keySize: RSAKey.KeySize) throws -> (PrivateKey, PublicKey) {

Where KeySize is a new extensible struct representing the supported key sizes.
This will generate an RSA public and private key pair for either 1024, 2048, 3073 or 4096 bits.

I have also added a field:

RSAKey.pemString

Which will return the pkcs#1 PEM string for either the public or private key.

I have also refactors the linux implementation to use d2i_PrivateKey_bio and d2i_PUBKEY_bio which solves issue #7. This simplifies the code since both apple and linux take the DER format and saves you from unnecessarily adding and removing headers.

Finally this fixes a bug with the AAD in GCM Encoding and decoding for 2048 and 3072 bit keys.

Motivation and Context

This solves issue #14 and #7 and has been implemented because users of SwiftJWT have requested the ability to dynamically generate RSA Keys for use in their projects.

How Has This Been Tested?

A new test has been added that generates keys for all the possible bits, exports the pemString and then uses the pemString to create new keys which are tested. This covers all the code paths added by this code.

Checklist:

  • I have submitted a CLA form
  • If applicable, I have updated the documentation accordingly.
  • If applicable, I have added tests to cover my changes.

Copy link
Collaborator

@billabt billabt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@billabt billabt merged commit 5ee6723 into master Apr 1, 2019
@djones6 djones6 deleted the makeKeys branch April 3, 2019 10:17
@Andrew-Lees11 Andrew-Lees11 mentioned this pull request May 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants