Skip to content

Instantly share code, notes, and snippets.

@komuw
Forked from lukebakken/rabbit_pash_hash.py
Created May 2, 2017 00:51
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komuw/c6fb1a1c757afb43fe69bdd736d5cf63 to your computer and use it in GitHub Desktop.
Save komuw/c6fb1a1c757afb43fe69bdd736d5cf63 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
from __future__ import print_function
import base64
import os
import hashlib
import struct
# This is the password we wish to encode
password = 'simon'
# 1.Generate a random 32 bit salt:
# This will generate 32 bits of random data:
salt = os.urandom(4)
# 2.Concatenate that with the UTF-8 representation of the password (in this case "simon")
tmp0 = salt + password.encode('utf-8')
# 3. Take the SHA256 hash and get the bytes back
tmp1 = hashlib.sha256(tmp0).digest()
# 4. Concatenate the salt again:
salted_hash = salt + tmp1
# 5. convert to base64 encoding:
pass_hash = base64.b64encode(salted_hash)
print(pass_hash)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment