Beispiel #1
0
        public void TestingUserId()
        {
            string secret = "SomeKey";

            byte[] key      = Encoding.UTF8.GetBytes(secret);
            long   interval = 1;

            var             hmacSha1  = new HashSha512();
            OneTimePassword generator = new OneTimePassword(key, hmacSha1);
            String          otp       = generator.Generate("user", interval);

            Assert.AreEqual(OneTimePassword.MAXIMUM_DIGITS, otp.Length);
            Assert.AreEqual("23297176", otp);
        }
Beispiel #2
0
        public void TestingOTPConstructorPassAllValues()
        {
            string secret = "SomeKey";

            byte[] key          = Encoding.UTF8.GetBytes(secret);
            int    returnDigits = 6;

            IHashAlgorithm  hmacSha1  = new HashSha512();
            OneTimePassword generator = new OneTimePassword(key, hmacSha1, returnDigits);

            Assert.IsNotNull(generator as OneTimePassword);
            Assert.AreEqual(returnDigits, generator.digits);
            Assert.AreEqual("HMACSHA512", generator.digest.ToString());
        }
Beispiel #3
0
        public void TestingSha512()
        {
            string secret = "SomeKey";

            byte[] key          = Encoding.UTF8.GetBytes(secret);
            long   interval     = 66778;
            int    returnDigits = 6;

            var             hmac      = new HashSha512();
            OneTimePassword generator = new OneTimePassword(key, hmac, returnDigits);
            String          otp       = generator.Generate("12345", interval);

            Assert.IsNotNull(otp);
            Assert.AreEqual(6, otp.Length);
            Assert.AreEqual("155083", otp);
        }