Created
January 11, 2017 00:07
-
-
Save ei-grad/782032245884298c38af1d47fccbe057 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| from base64 import b64decode | |
| from functools import reduce | |
| from hashlib import md5 | |
| from io import BytesIO | |
| import struct | |
| BEUInt32 = struct.Struct(">I") | |
| def read_int(f): | |
| return reduce(lambda a, b: (a << 8) + b, f.read(BEUInt32.unpack(f.read(4))[0])) | |
| def write_int(i): | |
| b = [] | |
| while i: | |
| b.append(i & 0xff) | |
| i >>= 8 | |
| if b[-1] & 128: | |
| b.append(0) | |
| return BEUInt32.pack(len(b)) + bytes(reversed(b)) | |
| def rsapub_fingerprint(line): | |
| f = BytesIO(b64decode(line.split()[1])) | |
| alg = f.read(BEUInt32.unpack(f.read(4))[0]) | |
| e = read_int(f) | |
| n = read_int(f) | |
| f = BytesIO() | |
| f.write(BEUInt32.pack(len(alg))) | |
| f.write(alg) | |
| f.write(write_int(e)) | |
| f.write(write_int(n)) | |
| return ':'.join('%02x' % i for i in md5(f.getvalue()).digest()) | |
| if __name__ == "__main__": | |
| import sys | |
| print(rsapub_fingerprint(open(sys.argv[1]).read())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment