0

我正在尝试实施 Salted Challenge Response Authentication Mechanism ( 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)。我有一个用于盐的字节数组。我需要做的只是位移 1 并将其添加到数组的末尾吗?

4

1 回答 1

1

您不能向数组中添加任何内容。由于数组是固定大小的,您需要为结果创建一个新数组。使用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);
于 2011-02-15T20:59:20.593 回答