I know RSA private key contains the information of the associated public key. How can I dump the public key from the private key? I want to do it in iOS environment without openssl. Is it possible?
Asked
Active
Viewed 687 times
0
-
What format is your private key in? – Duncan Jones Sep 29 '14 at 08:14
-
The private key is in PEM format. – yohon Sep 29 '14 at 08:28
-
PEM is an encoding, not a format. What *format* is your key in? – Duncan Jones Sep 29 '14 at 08:29
-
Sorry, you mean this "RSA/ECB/OAEPWithSHA-1AndMGF1Padding". – yohon Sep 29 '14 at 09:01
-
Nope. That's a mode of operation (a way of *using* a key). I want to know what format the key is in. For instance, if you created the key with OpenSSL, it may be an ASN.1 RSAPrivateKey object. – Duncan Jones Sep 29 '14 at 09:30
-
I see. Here is how the private key (PKCS#1) look like: -----BEGIN RSA PRIVATE KEY----- BASE64 ENCODED DATA -----END RSA PRIVATE KEY----- – yohon Sep 29 '14 at 09:42
1 Answers
0
yes it is possible ...
but you have to handle all the stuff about the way how the key is represented, i.e. how the specific parts of the key are stored in a file, etc
your private key consists of some numbers, usually like this: d (private exponent), N (common modulus) P,Q (two very large primes) dP and dQ (intermediate values for a computational shortcut ... ignore them for your task)
what you want to do is to calculate PHI = (P-1)*(Q-1) and then run the extended euclidean algorithm (see wikipedia for that) for d and PHI to find the multiplicative inverse element of d mod PHI ... this element is e (public exponent)
your public key then is the tuple (e, N)

DarkSquirrel42
- 10,167
- 3
- 20
- 31
-
Many private key formats store the public exponent as well. Which makes life considerably easier. – Duncan Jones Sep 29 '14 at 08:27
-
nope ... but it shouldn't be that hard to find something that breaks down your key into its parts ... look for open source stuff that handles keys like yours ... openssl for example ... maybe even this can help you https://www.openssl.org/docs/apps/asn1parse.html – DarkSquirrel42 Oct 02 '14 at 06:33