Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import hashlib
  2. from base64 import b64decode
  3.  
  4. def build_id(pub_key_pem):
  5. pub_key_der = b64decode(pub_key_pem)
  6. sha = hashlib.sha256(pub_key_der).hexdigest()
  7. prefix = sha[:32]
  8.  
  9. reencoded = ""
  10. ord_a = ord('a')
  11. for old_char in prefix:
  12. code = int(old_char, 16)
  13. new_char = chr(ord_a + code)
  14.  
  15. reencoded += new_char
  16.  
  17. return reencoded
  18.  
  19. def main():
  20. pub_key = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjvF5pjuK8gRaw/2LoRYi37QqRd48B/FeO9yFtT6ueY84z/u0NrJ/xbPFc9OCGBi8RKIblVvcbY0ySGqdmp0QsUr/oXN0b06GL4iB8rMhlO082HhMzrClV8OKRJ+eJNhNBl8viwmtJs3MN0x9ljA4HQLaAPBA9a14IUKLjP0pWuwIDAQAB'
  21.  
  22. id_ = build_id(pub_key)
  23. print(id_)
  24.  
  25. if __name__ == '__main__':
  26. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement