Implements the OATH HOTP algorithm.
 private void TestSHA1AndAssert(Key key, int digits, int counter, string expected)
 {
     var otp = new CounterBasedOtpGenerator(key, digits, new SHA1HMACAlgorithm());
     var result = otp.GenerateOtp(counter);
     Assert.AreEqual(expected, result);
 }
Exemple #2
0
 /// <summary>
 ///     Initializes a new instance of the TimeBasedOtpGenerator class. This
 ///     is used when the client and server do not share a counter
 ///     value but the clocks between the two are synchronized within
 ///     reasonable margins of each other.
 /// </summary>
 /// <param name="secretKey">The secret key.</param>
 /// <param name="otpLength">The number of digits in the OTP to generate.</param>
 /// <param name="hmacAlgorithm">The HMAC algorithm to use.</param>
 public TimeBasedOtpGenerator(Key secretKey, int otpLength, IHMACAlgorithm hmacAlgorithm)
 {
     this.counterOtp = new CounterBasedOtpGenerator(secretKey, otpLength, hmacAlgorithm);
 }
 private string GetOtpWithImplicitHMAC(Key key, int digits, int counter)
 {
     var otp = new CounterBasedOtpGenerator(key, digits);
     return otp.GenerateOtp(counter);
 }
 /// <summary>
 ///     Initializes a new instance of the TimeBasedOtpGenerator class. This
 ///     is used when the client and server do not share a counter
 ///     value but the clocks between the two are synchronized within
 ///     reasonable margins of each other.
 /// </summary>
 /// <param name="secretKey">The secret key.</param>
 /// <param name="otpLength">The number of digits in the OTP to generate.</param>
 /// <param name="hmacAlgorithm">The HMAC algorithm to use.</param>
 public TimeBasedOtpGenerator(Key secretKey, int otpLength, IHMACAlgorithm hmacAlgorithm)
 {
     this.counterOtp = new CounterBasedOtpGenerator(secretKey, otpLength, hmacAlgorithm);
 }