agens-no / EllipticCurveKeyPair

Sign, verify, encrypt and decrypt using the Secure Enclave
Other
708 stars 114 forks source link

Can I export the EC Private key ? #37

Open preetigaur opened 5 years ago

preetigaur commented 5 years ago

I need to export the EC Private Key as I need to send the private key to my server in encrypted format? Any help is appreciated. Thanks

hfossli commented 5 years ago

This is currently not supported in this code base. If you want to we can make it happen! Are you a representing a company? We are considering opening up a patreon account. If you would like to know more about why we think a support contract is a good idea we support the rationale presented in these tweets. Would you be interested in supporting us?

We will anyways try our best to have a helpful and meaningful discussion. When it comes to your question it should be possible. Note that it is not possible to export nor import private keys stored on the secure enclave. So it would need to be stored in keychain. It should be fairly simple to get the raw data of the private key, but as you might have seen https://github.com/agens-no/EllipticCurveKeyPair/blob/a339b41428e0be9cb63291f7216645608a7c8605/Sources/EllipticCurveKeyPair.swift#L518-L541 it is wise to structure the values in a format openssl and other libraries understand well. Some of the work would probably mean getting this right which may or may not be trivial.

Looking forward to hear from you

rustymagnet3000 commented 5 years ago

why would you want to do that @preetigaur ? The private key is your part of a non-repudiation claim...(i.e. the private key never leaves the leave possession of the holder, unless they lose phone and somebody compromises the device authentication).

The public key can be exported and shared with the server for verifying signatures of encrypting small payloads to be decrypted locally inside the iOS Secure Enclave.