Git Product home page Git Product logo

Comments (4)

hadley avatar hadley commented on August 22, 2024

For example, my public key (also found at https://api.github.com/users/hadley/keys) is:

pubkey <- "-----BEGIN PUBLIC KEY-----
MIIBIDANBgkqhkiG9w0BAQEFAAOCAQ0AMIIBCAKCAQEAy/i7l7DZon6YFnZfXg/H
+BnYDOG9CkHWtSxKXLiAlygl7kqF5tTeUHapMFCnkE1OLFOCGJCFT2PCi/Yipc2Y
AMghko/jcPT8Qa1hQaY+z4ErTqt6DllI7OZkakhphV96q9gUxcln2WXWU/6MD7H3
yetn60b5xH53SSVDfu1mSwosiaxio8aeIv84cIrjg4yUeKsUYOjkr3bNmkx478LV
q2y3aj//OpemfEVyp0BHpx8govAitKVU+p4z/4t/o4T0W8mAsqs9M1O6MYFthC+W
6FuvR61cYo40qO4YZ3jcRgzGCWgXuZWG4RvwNM+BEY9BGvEWLcjtplntnfeSyOCA
uQIBIw==
-----END PUBLIC KEY-----"

parsed <- PKI::PKI.load.key(textConnection(pubkey))

der <- PKI::PKI.save.key(parsed, "DER")
PKI::PKI.digest(key, "MD5")
# [1] 82 3b 28 6f 24 1a c5 0b 77 c6 4d ed 26 4b a8 c4

but github tells me my finger print is ff:1d:8e:1c:af:f9:02:f7:6e:55:ca:cd:22:c4:5b:e6

from pki.

s-u avatar s-u commented on August 22, 2024

It is the MD5 hash of the SSH-encoded key (in binary form) - so for your key

> q = "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvPJWA/qBXtSCwvYopyXdD28C4pC2PBm3GZOoZ4XxGm4UIKZWp+bJRfGEpfY+1peX8xFNy6V4bEoGkr2wNWFqP1aBdfEwlSKBdNskIsV2CCx1TRWZKvnauDtehfOJ5a7bTiHwzHYJVrnjNJbqi6VX8XqSF29uz5eDw7F1J+nZp5mHokvqQabJkNoacSDaLISKa/ig6EHSVKOrww+qf1hOlM8UmW0Cro/+v6VhNdguCdx+ByDICAoJzWGM2JuXLMOTZjADwkUpPJ5aNLQlgknUBK/WPXtpTbp/LAsHRhsmeJjr8FP3R3z4XhvDokeap7eFRQmLo6n4I8uBO3Vy9LqmVQ=="
> PKI.digest(base64decode(strsplit(q, " ", TRUE)[[1]][2]),"MD5")
 [1] ff 1d 8e 1c af f9 02 f7 6e 55 ca cd 22 c4 5b e6

Since we don't provide PKI.save.key in OpenSSH format it's a bit legwork to get it from raw keys, but possible:

> k <- PKI.load.OpenSSH.pubkey(q, format="key")
> der <- PKI.save.key(k, "DER")
> PKI.digest(unlist(lapply(c(list(charToRaw("ssh-rsa")), ASN1.decode(ASN1.decode(der)[[2]])[2:1]), function(o) c(writeBin(length(o), raw(), endian="big"), o))), "MD5")
 [1] ff 1d 8e 1c af f9 02 f7 6e 55 ca cd 22 c4 5b e6

Note: your key in pubkey above is not your github key.

BTW:the above would be much simpler if we had a way to get exp/mod from keys - sounds like a good idea ...

from pki.

hadley avatar hadley commented on August 22, 2024

Thanks Simon, that's super helpful.

I generated pubkey key from my the github public key using PKI.load.key and PKI.save.key - should I not expect to get the same key back? (albeit represented in a different way). Or have I made a silly mistake somewhere?

key <- "ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAvPJWA/qBXtSCwvYopyXdD28C4pC2PBm3GZOoZ4XxGm4UIKZWp+bJRfGEpfY+1peX8xFNy6V4bEoGkr2wNWFqP1aBdfEwlSKBdNskIsV2CCx1TRWZKvnauDtehfOJ5a7bTiHwzHYJVrnjNJbqi6VX8XqSF29uz5eDw7F1J+nZp5mHokvqQabJkNoacSDaLISKa/ig6EHSVKOrww+qf1hOlM8UmW0Cro/+v6VhNdguCdx+ByDICAoJzWGM2JuXLMOTZjADwkUpPJ5aNLQlgknUBK/WPXtpTbp/LAsHRhsmeJjr8FP3R3z4XhvDokeap7eFRQmLo6n4I8uBO3Vy9LqmVQ=="

parsed <- PKI::PKI.load.OpenSSH.pubkey(key, format = "key")
PKI::PKI.save.key(parsed)

from pki.

s-u avatar s-u commented on August 22, 2024

Probably some copy/paste issue - the key generated with the above is indeed your GitHub key and it shows the correct fingerprint -- but it is not identical to the pubkey in your original post on top.

from pki.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.