Created
January 17, 2020 23:04
-
-
Save junquera/e1aeb836d255b6968106ab9f93d4db69 to your computer and use it in GitHub Desktop.
Onion from public key
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
import hashlib | |
import base64 | |
from Crypto.PublicKey import RSA | |
import sys | |
# U=$(openssl rsa -in a.pem -pubout -outform DER | tail -c +23 | shasum | head -c 20 | python -c "import base64,sys; print base64.b32encode(sys.stdin.readline().strip('\n').decode('hex')).lower()"); echo "http://${U}.onion" | |
with open(sys.argv[1]) as f: | |
pem = f.read() | |
key = RSA.importKey(pem) | |
pub = key.publickey() | |
der = pub.exportKey('DER') | |
h = hashlib.sha1(der[22:]) | |
onion = base64.b32encode(h.digest())[:16] | |
print("%s.onion" % onion.decode().lower()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment