Skip to content

Instantly share code, notes, and snippets.

@rkrishnasanka
Created January 1, 2016 05:29
Show Gist options
  • Save rkrishnasanka/121fc6e48ed203cca1d7 to your computer and use it in GitHub Desktop.
Save rkrishnasanka/121fc6e48ed203cca1d7 to your computer and use it in GitHub Desktop.
import sys
import base64
import struct
key = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAADQ1IiOUdFSuqJ2l0fhs= root@kali'
# get the second field from the public key file.
keydata = base64.b64decode(
key.split(None)[1])
parts = []
while keydata:
# read the length of the data
dlen = struct.unpack('>I', keydata[:4])[0]
# read in <length> bytes
data, keydata = keydata[4:dlen+4], keydata[4+dlen:]
parts.append(data)
e_val = eval('0x' + ''.join(['%02X' % struct.unpack('B', x)[0] for x in parts[1]]))
n_val = eval('0x' + ''.join(['%02X' % struct.unpack('B', x)[0] for x in parts[2]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment