Exemple #1
0
 /// <remarks>
 /// This method mainly exists for unit tests.
 /// The RFC defines a decimal value in the test table that is an
 /// intermediate step to a final HOTP value
 /// </remarks>
 internal long ComputeHotpDecimal(long counter, OtpHashMode mode) => CalculateOtp(KeyUtilities.GetBigEndianBytes(counter), mode);
Exemple #2
0
 /// <summary>
 /// Takes a time step and computes a TOTP code
 /// </summary>
 /// <param name="counter">time step</param>
 /// <param name="mode">The hash mode to use</param>
 /// <returns>TOTP calculated code</returns>
 protected override string Compute(long counter, OtpHashMode mode) => Digits(CalculateOtp(KeyUtilities.GetBigEndianBytes(counter), mode), _totpSize);
Exemple #3
0
 /// <summary>
 /// Uses the procedure defined in RFC 4226 section 7.5 to derive a key from the master key
 /// </summary>
 /// <param name="masterKey">The master key from which to derive a device specific key</param>
 /// <param name="serialNumber">A serial number that is unique to the authenticating device</param>
 /// <param name="mode">The hash mode to use.  This will determine the resulting key lenght.  The default is sha-1 (as per the RFC) which is 20 bytes</param>
 /// <returns>Derived key</returns>
 public static byte[] DeriveKeyFromMaster(IKeyProvider masterKey, int serialNumber, OtpHashMode mode = OtpHashMode.Sha1) => DeriveKeyFromMaster(masterKey, KeyUtilities.GetBigEndianBytes(serialNumber), mode);