Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Last active August 12, 2020 23:37
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xeoncross/5326443 to your computer and use it in GitHub Desktop.
Save xeoncross/5326443 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
@ferielboa
Copy link

i'd like to know how i could complie this code, can i use the Cmd of windows.
Please could u write me down the command line.
Thanks

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