Skip to content

Instantly share code, notes, and snippets.

@yidas
Last active August 22, 2019 08:54
Show Gist options
  • Save yidas/32bdfb36ab8279497ae4a34d01e5e27b to your computer and use it in GitHub Desktop.
Save yidas/32bdfb36ab8279497ae4a34d01e5e27b to your computer and use it in GitHub Desktop.
Public key's fingerprint formula

Public key's fingerprint formula

The public key file (key.pub) contains the binary key that is packaged into a base64 string.

Formula

The public key's fingerprint formula:

# SHA256
Base64Encode( SHA256( Base64Decode( base64-key-string ) ) )

# MD5
MD5-HEX( Base64Decode( base64-key-string ) )

PHP sameple:

$publicKeyContent = "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPMYhoA2ICw6rVutJ9CaF63NCUwE3KCB06JjScoVIfOQilV7y/s6I7ty765jaVXo8Thj8ePVwy6whivI8NbZ8UY=";

$fingerPrint = base64_encode(hash('sha256', base64_decode($publicKeyContent), true));

// MD5
$fingerPrintMD5 = md5(base64_decode($publicKeyContent));

The $fingerPrint should same as the fingerprint in SSH connection: Server host key: ecdsa-sha2-nistp256 SHA256:AcrTsZ7KfsKzak2d68qCJKdXrZ+9TOhfr0/J3BMAa8U

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment