Created
December 8, 2021 15:45
-
-
Save c3c/0c965908f39c8795dd7b484016c2e18e to your computer and use it in GitHub Desktop.
Conversion of identity hashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from base64 import b64decode,b64encode | |
from struct import pack,unpack | |
from binascii import hexlify | |
import sys | |
def u32(x): return unpack(">I", x)[0] | |
def p32(x): return pack(">I", x) | |
hash = b64decode(sys.argv[1]).replace(b"-",b"") | |
assert len(hash) == 61 | |
version = hash[0] | |
assert version == 0x01 | |
prf = ['sha1','sha256','sha512'][u32(hash[1:][:4])] # KeyDerivationPrf | |
iterations = u32(hash[5:][:4]) | |
salt_len = u32(hash[9:][:4]) | |
salt = b64encode(hash[13:][:salt_len]).decode() | |
subkey = b64encode(hash[13+salt_len:]).decode() | |
print(f"{prf}:{iterations}:{salt}:{subkey}") | |
## reverse, create the b64 hash | |
## e.g. use to generate: https://8gwifi.org/pbkdf.jsp | |
salt = b64decode("xx") | |
subkey = b64decode("xx") | |
salt_len = p32(len(salt)) | |
iterations = p32(10000) | |
prf = p32(0x01) | |
version = b'\x01' | |
hash = version+prf+iterations+salt_len+salt+subkey | |
print(b64encode(hash)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment