dashton82 / Otp.NET

.NET Implementation of HOTP and TOTP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Otp.NET

One-Time password library, providing .NET implementations of HOTP (RFC4226) and TOTP (RFC6238)

The Implementations of both algorithms is based on the reference implementations listed in the relevant RFC.

How to get it

You can install the package from nuget.org

Install-Package simonbu11.otp

Usage

HOTP

Create a generator

var generator = new HmacSha1HotpGenerator(new HotpGeneratorSettings
{
    SharedSecret = OtpSharedSecret.FromAsciiString(sharedSecret)
});

generate code from counter

var counter = 1;
var code = generator.Generate(counter);

TOTP

Create a generator

// There are 3 TOTP generator implementations - HmacSha512TotpGenerator, HmacSha256TotpGenerator & HmacSha1TotpGenerator
var generator = new HmacSha512TotpGenerator(new HotpGeneratorSettings
{
    SharedSecret = OtpSharedSecret.FromAsciiString(sharedSecret)
});

Then either generate a code from a specific time

var time = DateTime.Now;
var actual = generator.Generate(time)

Or either generate a code from a specific time-step

var timeStep = 1234567890;
var actual = generator.Generate(timeStep)

## License This project is licensed under the MIT license, you can find a copy of the license in the LICENSE file.

About

.NET Implementation of HOTP and TOTP

License:MIT License


Languages

Language:C# 52.0%Language:F# 47.3%Language:Batchfile 0.7%