Skip to content

Instantly share code, notes, and snippets.

@vaachii
Last active August 29, 2015 14:10
Show Gist options
  • Save vaachii/95d04d825086eecbb86a to your computer and use it in GitHub Desktop.
Save vaachii/95d04d825086eecbb86a to your computer and use it in GitHub Desktop.
[1417869776] Generate a salted SHA-1
# -*- coding: UTF-8 -*-
from hashlib import sha1
from binascii import hexlify
from base64 import b64encode
data = '0123456789abcdef'
try:
with open('/dev/urandom', 'rb') as fh:
salt = fh.read(4)
ssha = sha1(data + salt).digest() + salt
print 'HEX : %s' % hexlify(ssha)
print 'B64 : %s' % b64encode(ssha)
print 'LDAP: {SSHA}%s' % b64encode(ssha)
except:
pass
[user@linux ~]$ python 1417869776.py
HEX : 74c5911632ba9155527d5506201e8354588eef7980a89b03
B64 : dMWRFjK6kVVSfVUGIB6DVFiO73mAqJsD
LDAP: {SSHA}dMWRFjK6kVVSfVUGIB6DVFiO73mAqJsD
[user@linux ~]$ python 1417869776.py
HEX : 4b973111e63c25a2ab8bda360aaf8d3ff3cdc8e18fcbd3d7
B64 : S5cxEeY8JaKri9o2Cq+NP/PNyOGPy9PX
LDAP: {SSHA}S5cxEeY8JaKri9o2Cq+NP/PNyOGPy9PX
[user@linux ~]$ python 1417869776.py
HEX : 4f6c2a660597e340e1748cb6c3e7ffbf4a002f6912c373f9
B64 : T2wqZgWX40DhdIy2w+f/v0oAL2kSw3P5
LDAP: {SSHA}T2wqZgWX40DhdIy2w+f/v0oAL2kSw3P5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment