Skip to content

Instantly share code, notes, and snippets.

@s4w3d0ff
Created July 29, 2016 19:35
Show Gist options
  • Save s4w3d0ff/817f3a1c24738d29b7775f9386d3719a to your computer and use it in GitHub Desktop.
Save s4w3d0ff/817f3a1c24738d29b7775f9386d3719a to your computer and use it in GitHub Desktop.
Launches subprocess 'tor --hash-password' and returns the hashed password
from subprocess import Popen, PIPE
import logging
def genTorPassHash(password):
""" Launches a subprocess of tor to generate a hashed <password>"""
logging.info("Generating a hashed password")
torP = Popen(['tor', '--hush', '--hash-password', str(password)], stdout=PIPE, bufsize=1)
try:
with torP.stdout:
for line in iter(torP.stdout.readline, b''):
line = line.strip('\n')
if not "16:" in line:
logging.debug(line)
else:
passhash = line
torP.wait()
logging.info("Got hashed password")
return passhash
except Exception as e:
logging.exception(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment