Skip to content

Instantly share code, notes, and snippets.

@sudmed
Created June 6, 2023 13:11
Show Gist options
  • Select an option

  • Save sudmed/0cc49836f9fa567902b07d76003d35fe to your computer and use it in GitHub Desktop.

Select an option

Save sudmed/0cc49836f9fa567902b07d76003d35fe to your computer and use it in GitHub Desktop.

Revisions

  1. sudmed created this gist Jun 6, 2023.
    32 changes: 32 additions & 0 deletions generator.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    #!/usr/bin/env python3

    # 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
    import sys

    # This is the password we wish to encode
    password = sys.argv[1]

    # 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 plaintext password
    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.decode("utf-8"))