0

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?

yohon
  • 19
  • 4

1 Answers1

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