-
Notifications
You must be signed in to change notification settings - Fork 157
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
How do I actually import a public key from a string ? #37
Comments
There are (at least) two possible formats an RSA public key could be in. Can you tell me if the PEM encoded key begins with The former is PKCS#1, and the latter is PKCS#8. In either case it's fairly easy to parse. PKCS#1 RSA public keys are the (PEM encoding, starting with
PKCS#8 RSA public keys are the (PEM encoding, starting with
As you can see, PKCS#8 contains the PKCS#1 encoding, plus an additional header:
When Base64 encoded in a PEM wrapper, this header will be the following 32 Base64-encoded characters:
With that treated as a special case (i.e. hardcoded), the code needed to parse the remaining https://github.com/RustCrypto/signatures/blob/master/ecdsa/src/convert.rs I can also look into if BearSSL code for this already written, as that's where the above code was translated from anyway. |
The theory is nice and simple but in practice for someone who just has a pubkey and wants to encrypt something for it without holding too much technical knowledge parsing the entire thing seems not a practical option. |
@NikosEfthias I'm suggesting adding a feature to this crate to support parsing (and potentially serializing) PKCS#1 and/or PKCS#8 RSA public keys. |
No, I mean as far as I can tell this crate doesn't support either PKCS#1 or PKCS#8-formatted public keys, but it wouldn't be too difficult to add and also seems important. |
Oh, I see so I believe you can add a feature request flag to this ticket. |
Such a feature would be lovely, as for now I can't load any existing keys from a file and use them to enc/de-crypt. |
Yes, I would really like to see serialization and deserialization of the common formats as a feature |
In go you simply
pem.Decode
and thenx509.ParsePKIXPublicKey
the given byte slice and you get arsa.PublicKey
. However, in the rust world none of those libraries are actually compatible with each other so how do I import an existing public key?The text was updated successfully, but these errors were encountered: