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

Allow exporting the data back from PublicKey and PrivateKey #60

Closed
serieuxchat opened this issue Feb 23, 2017 · 6 comments
Closed

Allow exporting the data back from PublicKey and PrivateKey #60

serieuxchat opened this issue Feb 23, 2017 · 6 comments

Comments

@serieuxchat
Copy link

Currently we can instantiate, e.g., a PublicKey with Data or a PEM string, but we cannot get these representations back if we already have a PublicKey.

It would be very useful if it were possible to at least get the raw data back.

@ldiqual
Copy link
Contributor

ldiqual commented Feb 24, 2017

This is a great idea. Exposing the key data is definitely an easy thing to do, we'll need to make sure that users understand that the data is not the exact data that was provided when creating the key – since we strip the headers when adding to the iOS keychain. We could potentially have data and originalData too.

As for PEM/DER, this is definitely something we can have too and that doesn't seem too hard to implement. PEM is just the key data in base64 with a header + footer, DER is raw bytes (so you could just use the data field).

I'm tagging this issue as enhancement and unless someone volunteers to PR something, I'll tackle it whenever I have an hour. Thanks a lot for the proposal!

@serieuxchat
Copy link
Author

serieuxchat commented Feb 24, 2017

Thanks very much for your quick reply!

If you're short on time, you may also consider making it an open class (so that people can write extensions to it) or making some read-only properties public (e.g. 'reference' and 'tag' of the PublicKey). (The latter would make it possible to extract the data from SecKey with third party code.)

@ldiqual
Copy link
Contributor

ldiqual commented Mar 1, 2017

@serieuxchat With 5485e6a , SwiftyRSA now gives you readonly access to reference, data and dataWithoutHeader (public key only). You can check it out this way:

pod 'SwiftyRSA', :git => '[email protected]:TakeScoop/SwiftyRSA.git', :branch => 'master'

I'll incrementally add support for exporting to PEM/DER and init with a SecKey. Thanks a lot for your patience!

@ldiqual
Copy link
Contributor

ldiqual commented Mar 6, 2017

@serieuxchat I PR'd some code that adds support for data(), pemString() and base64String() here: #61. Feel free to jump in if you have any comment!

@serieuxchat
Copy link
Author

Thanks a lot! We will give it a try.

@ldiqual
Copy link
Contributor

ldiqual commented Apr 11, 2017

@serieuxchat Good news! SwiftyRSA 1.1.0 has been pushed to cocoapods and now allows exporting data from a private or public key. Let me know if you run into any issue! Closing this now

@ldiqual ldiqual closed this as completed Apr 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants