Skip to content

Instantly share code, notes, and snippets.

@sergeycherepanov
Forked from xeoncross/fingerprint.php
Created February 3, 2016 20:22
Show Gist options
  • Save sergeycherepanov/7e88422f53eb4cd09960 to your computer and use it in GitHub Desktop.
Save sergeycherepanov/7e88422f53eb4cd09960 to your computer and use it in GitHub Desktop.
Generate a fingerprint from and RSA SSH public key
<?php
print "\n";
$rsa = file_get_contents('rsa.pub');
$ssh = file_get_contents('ssh.pub');
// For reference
print $rsa . "\n\n";
print $ssh . "\n\n";
print exec('ssh-keygen -lf ssh.pub') . "\n\n"; // What should be correct
// Get the middle part out, decode it, and hash it
$content = explode(' ', $ssh, 3);
print join(':', str_split(md5(base64_decode($content[1])), 2)) . "\n\n";
/* Output:
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbIEIZZ1TOwy4eJyk5XK5chARj
nGJnfvJUbDBrDuyYqPsAgX/uoHWV/T8XN80cwpTcLalfS2lYsBrEy75w4o2vfto6
VCIFKG2w5anABC0BVB52DBUGXp1x1gGU4RZ3VNdQAmeMaJijzoCpkRb6+uD9pw2w
rlnmSiNINdBXYmC2fwIDAQAB
-----END PUBLIC KEY-----
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCbIEIZZ1TOwy4eJyk5XK5chARjnGJnfvJUbDBrDuyYqPsAgX/uoHWV/T8XN80cwpTcLalfS2lYsBrEy75w4o2vfto6VCIFKG2w5anABC0BVB52DBUGXp1x1gGU4RZ3VNdQAmeMaJijzoCpkRb6+uD9pw2wrlnmSiNINdBXYmC2fw== phpseclib-generated-key
1024 27:0a:59:be:74:ff:6d:11:0a:9a:b6:cf:fe:fd:dc:d1 phpseclib-generated-key (RSA)
27:0a:59:be:74:ff:6d:11:0a:9a:b6:cf:fe:fd:dc:d1
^ WIN!
*/
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQCbIEIZZ1TOwy4eJyk5XK5chARjnGJnfvJUbDBrDuyYqPsAgX/uoHWV/T8XN80cwpTcLalfS2lYsBrEy75w4o2vfto6VCIFKG2w5anABC0BVB52DBUGXp1x1gGU4RZ3VNdQAmeMaJijzoCpkRb6+uD9pw2wrlnmSiNINdBXYmC2fw== phpseclib-generated-key
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment