0
$\begingroup$

I wrote application client-server. Now I would like to add safe connection.

First

When client connect to server - server send certificate in *.crt file.

Now I want to extract from this file the public key and validate certificate - check it is safe.

I use Lazarus/Delphi/Free Pascal

Can you tell me how can I extract from this file public key ready for use in hexadecimal (byte) format?

I know that in this file is $p$, $q$ and rest but I want final public key ready to use.

Maybe if not in my programming language then I can do this on my computer? Linxu, Windows?

How can I do this with private key? I have key in file with header:

-----BEGIN RSA PRIVATE KEY-----
$\endgroup$

closed as off-topic by Maarten Bodewes, otus, Biv, yyyyyyy, e-sushi Feb 9 '17 at 3:58

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions are off-topic even if you are writing or debugging cryptographic code. Unless your question is specifically about how the cryptographic algorithm or protocol works, you should look into asking on Stack Overflow instead." – Maarten Bodewes, otus, Biv, yyyyyyy, e-sushi
If this question can be reworded to fit the rules in the help center, please edit the question.

2
$\begingroup$

It is very easy to do this with openssl.

Say foo.crt is your crt file. Then,

$ openssl x509 -in foo.crt -text -noout

will print all the necessary information (issuer, pkey : modulus rsa and exponent, signature algorithm etc) in text format.

If you give

$ openssl x509 -in foo.crt -text -noout > foo.txt

you will save the previous information to foo.txt file.

To answer your question

Can you tell me how can I extract from this file public key ready for use in hexadecimal (byte) format?

one way to do this is first export the public key and then convert it to hex form

  $ openssl x509 -in foo.crt  -noout -pubkey > foo-public
  $ openssl rsa -noout -text  -in foo-public -pubin > foo-public-hex

Now foo-public-hex contains your pkey in hex format.

Then you wrote

I know that in this file is p, q and rest but I want final public key ready to use.

I am not sure I follow you... the private key is not in the .crt file but in .key file and server wont sent it to the client.

If foo.key is you private key then giving

$openssl rsa -noout -text  -in foo.key

you will see the private exponent and the primes p,q in hex form.

$\endgroup$
  • $\begingroup$ Nitpick: openssl commandline is available for and works the same on all Unixes and Windows, not just LInux. VMS is a little different, but not much. $\endgroup$ – dave_thompson_085 Feb 9 '17 at 6:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.