Skip to content

Instantly share code, notes, and snippets.

@lukebakken
Forked from komuw/rabbit_pash_hash.py
Last active May 2, 2017 00:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lukebakken/0aab923350a2bd6bbc9dbe3dde4a9a7f to your computer and use it in GitHub Desktop.
Save lukebakken/0aab923350a2bd6bbc9dbe3dde4a9a7f 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