我正在尝试实现咸化挑战响应身份验证机制(RFC 5802),但我遇到了一些问题。
Hi(str, salt, i):
U1 := HMAC(str, salt + INT(1))
U2 := HMAC(str, U1)
...
Ui-1 := HMAC(str, Ui-2)
Ui := HMAC(str, Ui-1)
Hi := U1 XOR U2 XOR ... XOR Ui
where "i" is the iteration count, "+" is the string concatenation
operator, and INT(g) is a 4-octet encoding of the integer g, most
significant octet first.我不确定如何添加INT(1)。我有一个salt的字节数组。我所需要做的就是将1位移位并将其添加到数组的末尾?
发布于 2011-02-16 04:59:21
您不能向数组中添加任何内容。由于数组的大小是固定的,因此您需要为结果创建一个新的数组。使用BitConverter类获取整数的二进制表示形式:
// create new array
byte[] key = new byte[salt.Length + 4];
// copy salt
Array.Copy(salt, key, salt.Length);
// create array from integer
byte[] g = BitConverter.GetBytes(1);
if (BitConverter.IsLittleEndian) {
Array.Reverse(g);
}
// copy integer array
Array.Copy(g, 0, key, salt.Length, 4);https://stackoverflow.com/questions/5009229
复制相似问题