concatenateUserIdAndPassword function
Concatenates user ID and password for RFC5054-compliant KDF input.
Returns userId:password
if userIdBytes
is non-null, else just passwordBytes
.
This is the input (I | ':' | p) of the first hash which RFC5054 uses to derive the user private key using a hash-based KDF:
x = H(s, H(I | ':' | p))
More secure KDFs can also make use of this concatenation as input without necessarily using the RFC5054 first or second hash.
Parameters:
userIdBytes
: Optional UTF-8 encoded user identifier bytes.passwordBytes
: UTF-8 encoded password bytes.
Returns: userIdBytes + ':' + passwordBytes
if userIdBytes provided,
otherwise just passwordBytes
.
Implementation
Uint8List concatenateUserIdAndPassword(
Uint8List? userIdBytes, Uint8List passwordBytes
) {
if (userIdBytes != null) {
const colonByte = 0x3A; // ASCII colon character
return Uint8List.fromList([
...userIdBytes,
colonByte,
...passwordBytes,
]);
} else {
return passwordBytes;
}
}