HMAC-en fonction d'un mot de passe en C# (RFC 4226 - HOTP)

Je suis d'essayer d'envelopper mon cerveau autour de la génération d'un 6 chiffres/caractères non sensible à la casse expiration de mot de passe.

Ma source est http://tools.ietf.org/html/rfc4226#section-5

D'abord la définition des paramètres

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.

Ensuite, nous avons l'algorithme pour générer les 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))

Ensuite, nous avons Tronquer défini comme

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

Et ensuite un exemple est proposé pour un 6 chiffres 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) ;

Je suis plutôt à une perte en tentant de convertir ce utile de code C# pour générer une seule fois les mots de passe. J'ai déjà le code pour la création d'une expirant HMAC comme suit:

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);

Je ne suis pas sûr de savoir comment aller de cela, à 6 chiffres proposés dans les algorithmes ci-dessus.

Je crois que C est un DateTime timbre et K est le secret de la Clé que j'ai déjà attribué à chaque compte utilisateur. Comment j'ai correctement hachage et puis tronquer jusqu'à 6 chiffres est là que je suis confus.
L'annexe C fournit une implémentation de référence en Java qui doit être facilement traduisible en C#.
Il est, mais il ne génère un numérique HOTP. J'aimerais vraiment un alpha-numérique HOTP.

OriginalL'auteur Josh | 2010-11-29