Pergunta

I need to extract modulus, private exponent, public exponent, primes, etc. from an RSA private key given in PEM format. This is for an embedded system where I cannot install any crypto or RSA libraries on the target system, so everything should be done in native C. Any pointers to existing code or hints how this is efficiently done would be appreciated.

Foi útil?

Solução

PEM file contains der encoded RSA Private Key in base64 format.

First you have to base64 decode it to get the original der encoded bytes. Then you have to parse the der encoded data.

As suggested by Lie Ryan, you can statically link some C libraries to do this. Or you can refer to the source codes of an existing library and write your own parser to do that.

For a light-weight library, I recommend looking at libtomcrypto's der routines in case you are going to write your own parser.

The same library also contains functions for base64 encoding and decoding.

Outras dicas

If you cannot or do not want to install the libraries into the target system, then you can just statically link the library while compiling.

Statically linking a library packs the library's code in the main executable.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top