Here is the easy way in bash (and openssl) to get the X.509 SubjectPublicKeyInfo block, DER-encoded:
openssl rsa -pubout -outform DER < "$pem" > "$pub" 2>/dev/null
Where $pem
is the private key file, RSA encoded.
To get the SHA256 Digest you need to run the following on the file resulting from the previous line:
openssl dgst -sha256 $pub | awk '{print $2}' | cut -c 0-32
All that remains is to take the resulting 32 char string and change it from regular hex ([0-9][a-f]) to ([a-p]) where a
matches 0
and p
matches f
.
With a bit of effort, I'm pretty sure these two steps could be made into a one-liner. I hope you find it helpful and if so, please let me know.