Hi,
Sorry for the necrobump, but for the records I also needed this (for a different reason than OP), so I came up with the following python script to generate hashes suitable for QBittorrent config file:
Code: Select all
import base64
import getpass
import hashlib
import os
# As per https://github.com/qbittorrent/qBittorrent/blob/ce9bdaef5cdb8ab77d71481f20b25c9e6da1b9eb/src/base/utils/password.cpp#L48
ITERATIONS = 100_000
# 4x32 bits words = 16 bytes: https://github.com/qbittorrent/qBittorrent/blob/ce9bdaef5cdb8ab77d71481f20b25c9e6da1b9eb/src/base/utils/password.cpp#L75
SALT_SIZE = 16
# Prompt user for password
password = getpass.getpass()
# Generate a cryptographically secure pseudorandom salt
salt = os.urandom(SALT_SIZE)
# PBKDF2 w/ SHA512 hmac
h = hashlib.pbkdf2_hmac("sha512", password.encode(), salt, ITERATIONS)
# Base64 encode and join salt and hash
print(f"Hash: {base64.b64encode(salt).decode()}:{base64.b64encode(h).decode()}")
To sum it up, it's a standard PBKDF2 with a SHA512 hmac, 100.000 iterations, and a 128bits salt. The salt is base64 encoded as well as the hash, and the two are joined together with the "
:" character (probably in an external config serialization step). The resulting string can be used directly in config like so:
Code: Select all
WebUI\Password_PBKDF2="@ByteArray(<hash as returned by the script>)"
so in practice, "
password123" coud be (depending on the salt):
Code: Select all
WebUI\Password_PBKDF2="@ByteArray(q+12KDUV69nIdoK92Alh7Q==:HtvIsWsCSN9PnE/gayIruCDeDjnz8TXG+Cw2XUTWs1CJFRXQxyyOyz/FVyU9QtTgEJ9fwxZYJKHaURV42sB0JQ==)"
Hope that'll help someone. Maybe not. Maybe future me

.