hotp 0.1.0

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

An implementation of the HMAC-based One-time Password (HOTP).

HMAC-based One-time Password (HOTP)

This is an implementation of the HOTP algorithm as specified in RFC 4226.

pub version

Installation

dart pub add hotp

Usage

final hotp = Hotp(secret: '12345678901234567890'.codeUnits);

// Generate a HOTP
final password = hotp.generate(counter: 0); // 755224

Base32 encoding

final hotp = Hotp.fromBase32('GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ');

print(hotp.generate(counter: 0)); // 755224

Supported algorithms

  • SHA1 - default, as specified in RFC 4226
  • SHA256
  • SHA512

APIs

Constructor parameters

NameTypeDescription
secretList<int>The secret key.
algorithmAlgorithmThe algorithm to use.
digitsintThe number of digits to generate.

If you want to use a Base32 encoded secret, use the fromBase32 constructor.

NameTypeDescription
secretStringThe Base32 encoded secret key.
digitsintThe number of digits to generate.
algorithmAlgorithmThe algorithm to use.
encodingEncodingThe encoding to use.

Methods

NameReturn typeDescription
generateintGenerates a HOTP for the given counter.
validateboolValidates a HOTP for the given counter.

Exported other package types

NameTypeDescription
base32classBase32 encoding and decoding util
EncodingintBase32 encoding and decoding alg

License

The project is licensed under the MIT license.