Я пытаюсь обернуть мозг вокруг создания шестизначного/персонального, не чувствительного к регистру, одноразового пароля.Одноразовый пароль на основе HMAC в C# (RFC 4226 - HOTP)
Мой источник http://tools.ietf.org/html/rfc4226#section-5
Первое определение параметров
C 8-byte counter value, the moving factor. This counter
MUST be synchronized between the HOTP generator (client)
and the HOTP validator (server).
K shared secret between client and server; each HOTP
generator has a different and unique secret K.
T throttling parameter: the server will refuse connections
from a user after T unsuccessful authentication attempts.
Тогда мы имеем алгоритм для генерации HOTP
As the output of the HMAC-SHA-1 calculation is 160 bits, we must
truncate this value to something that can be easily entered by a
user.
HOTP(K,C) = Truncate(HMAC-SHA-1(K,C))
Тогда мы Округление определяется как
String = String[0]...String[19]
Let OffsetBits be the low-order 4 bits of String[19]
Offset = StToNum(OffsetBits) // 0 <= OffSet <= 15
Let P = String[OffSet]...String[OffSet+3]
Return the Last 31 bits of P
А затем пример предлагается для 6 цифр HOTP
The following code example describes the extraction of a dynamic
binary code given that hmac_result is a byte array with the HMAC-
SHA-1 result:
int offset = hmac_result[19] & 0xf ;
int bin_code = (hmac_result[offset] & 0x7f) << 24
| (hmac_result[offset+1] & 0xff) << 16
| (hmac_result[offset+2] & 0xff) << 8
| (hmac_result[offset+3] & 0xff) ;
я скорее в недоумении, пытаясь преобразовать его в полезный код C# для генерации одноразовых паролей. У меня уже есть код для создания истекающей HMAC следующим образом:
byte[] hashBytes = alg.ComputeHash(Encoding.UTF8.GetBytes(input));
byte[] result = new byte[8 + hashBytes.Length];
hashBytes.CopyTo(result, 8);
BitConverter.GetBytes(expireDate.Ticks).CopyTo(result, 0);
Я просто не знает, как идти от, до 6 цифр, как это предлагается в приведенных выше алгоритмах.
Я считаю, что C является DateTime марка и K является секретным ключом я уже назначены на счет каждого пользователя. Что касается того, как я правильно их хэш, а затем урезать до 6 цифр, я смущен. – Josh 2010-11-29 21:02:53
Приложение C предоставляет ссылочную реализацию на Java, которая должна быть легко переводимой на C#. – dtb 2010-11-29 21:06:09
Это, но он генерирует только число HOTP. Мне бы очень понравился альфа-числовой HOTP. – Josh 2010-11-29 21:26:37