Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get SHA256 hash of public key

I have a certificate mycert.pem . I got the public key of the certificate by command:

openssl x509 -pubkey -noout -in mycert.pem  > pubkey.pem

How can I get the SHA256 hash of the public key?

like image 288
Leem Avatar asked Mar 19 '18 14:03

Leem


People also ask

How do I find public key hash?

How do you create a public key hash ? Just take your public key and put it through the SHA256 and RIPEMD160 hash functions: It's sometimes referred to as a HASH160(publickey) , because that's simpler than writing RIPEMD160(SHA256(publickey)) . That's it.

How do I create an SSH key?

Open a terminal and use the ssh-keygen command with the -C flag to create a new SSH key pair. Replace the following: KEY_FILENAME : the name for your SSH key file. For example, a filename of my-ssh-key generates a private key file named my-ssh-key and a public key file named my-ssh-key.

Is private key SHA256?

SHA256 is a one way hash function it is not directly related to public or private key. There is no such thing as a SHA256 key pair. 2. Yes, this is a problem and storing data encryption keys in the same database as the ciphertext doesn't provide any security.


2 Answers

You can use ssh-keygen. Convert file format first

ssh-keygen -i -m PKCS8 -f pubkey.pem > NEWpubkey.pem

Next get the fingerprint

ssh-keygen -lf NEWpubkey.pem

Get type inference

2048 SHA256:hYAU9plz1WZ+H+eZCushetKpeT5RXEnR8e5xsbFWRiU no comment (RSA)

like image 152
uanr81 Avatar answered Sep 20 '22 15:09

uanr81


The openssl -pubkey outputs the key in PEM format (even if you use -outform DER).

Assuming you have a RSA public key, you have to convert the key in DER format (binary) and then get its hash value:

 openssl rsa -in pubkey.pem -pubin -outform der | openssl dgst -sha256
like image 34
oliv Avatar answered Sep 19 '22 15:09

oliv