Files
modernkeepasslib/ModernKeePassLib.Test/Cryptography/HmacOtpTests.cs

32 lines
851 B
C#
Raw Normal View History

2019-07-25 16:39:43 +02:00
using System.Text;
using ModernKeePassLib.Cryptography;
using NUnit.Framework;
2019-07-25 16:39:43 +02:00
namespace ModernKeePassLib.Test.Cryptography
{
[TestFixture]
2019-07-25 16:39:43 +02:00
public class HmacOtpTests
{
// Using the test case from Appendix D of RFC 4226
private const string Secret = "12345678901234567890";
2019-07-25 16:39:43 +02:00
private static readonly string[] ExpectedHotp = {
2019-07-25 16:39:43 +02:00
"755224", "287082", "359152", "969429", "338314",
"254676", "287922", "162583", "399871", "520489"
};
[Test]
2019-07-25 16:39:43 +02:00
public void TestGenerate()
{
var secretBytes = Encoding.UTF8.GetBytes(Secret);
2019-07-25 16:39:43 +02:00
for (ulong i = 0; i < 10; i++)
{
var hotp = HmacOtp.Generate(secretBytes, i, 6, false, -1);
Assert.That(ExpectedHotp[i], Is.EqualTo(hotp));
2019-07-25 16:39:43 +02:00
}
}
}
}