我正在尝试了解采取OpenSSH公钥的步骤,如下所示:
SSH-RSA AAAAB3NzaC1yc2EAAAABIwAAAQEAqmEmDTNBC6O8HGCdu0MZ9zLCivDsYSttrrmlq87 / YsEBpvwUTiF3UEQuFLaq5Gm + dtgxJewg / UwsZrDFxzpQhCHB6VmqrbKN2hEIkk / HJvCnAmR1ehXv8n2BWw3Jlw7Z + VgWwXAH50f2HWYqTaE4qP4Dxc4RlElxgNmlDPGXw / dYBvChYBG / RvIiTz1L + pYzPD4JR54IMmTOwjcGIJl7nk1VjKvl3D8Wgp6qejv4MfZ7Htdc99SUKcKWAeHYsjPXosSk3GlwKiS / sZi51Yca394GE7T4hZu6HTaXeZoD8 + IZ7AijYn89H7EPjuu0iCAa / cjVzBsFHGszQYG + U5KfIw ==
然后将其转换为标准指纹,如下所示:
2048 49:d3:cb:f6:00:d2:93:43:a6:27:07:ca:12:fd:5d:98 id_rsa.pub (RSA)
我试图深入研究OpenSSH源码以了解这一点,但是这让我头疼。我的第一个猜测是在键文本上执行简单的MD5,但结果与上述输出不匹配。
它是base64编码密钥的MD5和:
import base64 import hashlib def lineToFingerprint(line): key = base64.b64decode(line.strip().split()[1].encode('ascii')) fp_plain = hashlib.md5(key).hexdigest() return ':'.join(a+b for a,b in zip(fp_plain[::2], fp_plain[1::2]))