Albireo.Otp.Hotp.GetCode C# (CSharp) Method

GetCode() public static method

Compute the one-time code for the given parameters.
public static GetCode ( HashAlgorithm algorithm, string secret, long counter, int digits = Otp.DefaultDigits ) : int
algorithm HashAlgorithm The hashing algorithm for the HMAC computation.
secret string The ASCII-encoded base32-encoded shared secret.
counter long The counter for which the one-time code must be computed.
digits int The number of digits of the one-time code.
return int
        public static int GetCode(
            HashAlgorithm algorithm,
            string secret,
            long counter,
            int digits = Otp.DefaultDigits)
        {
            Contract.Requires<ArgumentOutOfRangeException>(Enum.IsDefined(typeof(HashAlgorithm), algorithm));
            Contract.Requires<ArgumentOutOfRangeException>(algorithm != HashAlgorithm.Unknown);
            Contract.Requires<ArgumentNullException>(secret != null);
            Contract.Requires<ArgumentOutOfRangeException>(counter >= 0);
            Contract.Requires<ArgumentOutOfRangeException>(digits > 0);
            Contract.Ensures(Contract.Result<int>() > 0);
            Contract.Ensures(Contract.Result<int>() < Math.Pow(10, digits));

            return Otp.GetCode(algorithm, secret, counter, digits);
        }