Skip to content

Instantly share code, notes, and snippets.

@komuw
Last active April 28, 2017 18:40
Show Gist options
  • Save komuw/051e314df19fd2ceb9419df8f9af3193 to your computer and use it in GitHub Desktop.
Save komuw/051e314df19fd2ceb9419df8f9af3193 to your computer and use it in GitHub Desktop.
rabbitMQ password hashing algo
# rabbitMQ password hashing algo as laid out in: http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/2011-May/012765.html
#1.Generate a random 32 bit salt:
import os
salt = os.urandom(32)
salt = ''.join(x.encode('hex') for x in salt)
salt = salt.upper()
#2.Concatenate that with the UTF-8 representation of the password (in this case "simon")
simon = ''.join(x.encode('hex') for x in 'simon')
utf_rep = salt+simon
utf_rep = utf_rep.upper()
#3. Take the MD5 hash
import hashlib
hash = hashlib.md5(utf_rep).hexdigest()
hash = ''.join(x.encode('hex') for x in hash)
hash = hash.upper()
#4. Concatenate the salt again:
salted_hash = salt+hash
salted_hash = salted_hash.upper()
#5. convert to base64 encoding:
import base64
pass_hash = base64.b64encode(salted_hash)
print pass_hash
#6. end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment