genotp_flutter 0.0.2 copy "genotp_flutter: ^0.0.2" to clipboard
genotp_flutter: ^0.0.2 copied to clipboard

TOTP/HOTP one-time password plugin for Flutter, powered by genotp-go via gomobile. Works on Android and iOS with no network dependency.

genotp_flutter #

Flutter plugin for TOTP/HOTP one-time password generation and verification, powered by genotp-go via gomobile.

Supports Android and iOS. The cryptographic engine runs natively on-device — no network call required.

Platform support #

Android iOS
24+ 13+

Installation #

dependencies:
  genotp_flutter: ^0.0.1

Usage #

Generate a new secret #

import 'package:genotp_flutter/genotp_flutter.dart';

final secret = await GenotpFlutter.generateSecret();
// e.g. "JBSWY3DPEHPK3PXP"

Generate a TOTP code #

final code = await GenotpFlutter.generateTotp(secretB32: secret);
// e.g. "123456"

With custom parameters:

final code = await GenotpFlutter.generateTotp(
  secretB32: secret,
  algorithm: 0, // 0=SHA1  1=SHA256  2=SHA512
  digits: 6,
  period: 30,
);

Verify a TOTP code #

final valid = await GenotpFlutter.verifyTotp(
  secretB32: secret,
  code: userInput,
);

With custom window tolerance (default window=1 allows +-1 period skew):

final valid = await GenotpFlutter.verifyTotp(
  secretB32: secret,
  code: userInput,
  window: 1,
);

Build an otpauth:// URI for QR code display #

final uri = await GenotpFlutter.buildTotpUri(
  label: 'alice@example.com',
  secretB32: secret,
  issuer: 'MyApp',
);
// otpauth://totp/alice%40example.com?secret=...&issuer=MyApp&algorithm=SHA1&digits=6&period=30

Pass this URI to any QR code library to let users scan it into their authenticator app (Google Authenticator, Authy, etc.).

HOTP #

// Generate
final code = await GenotpFlutter.generateHotp(
  secretB32: secret,
  counter: 0,
);

// Build URI
final uri = await GenotpFlutter.buildHotpUri(
  label: 'alice@example.com',
  secretB32: secret,
  issuer: 'MyApp',
  counter: 0,
);

Algorithm constants #

Value Algorithm
0 SHA1 (default, widest compatibility)
1 SHA256
2 SHA512

Error handling #

All methods throw a PlatformException on failure (invalid secret, bad base32 encoding, etc.).

try {
  final code = await GenotpFlutter.generateTotp(secretB32: secret);
} on PlatformException catch (e) {
  print('OTP error: ${e.message}');
}

How it works #

Flutter (Dart)
    |  MethodChannel
Android (Kotlin)          iOS (Swift)
    |  mobile.Mobile.*        |  MobileNewTotpHandle()
genotp.aar                Genotp.xcframework
    |                         |
    +--- genotp-go (Go) ------+

The native binary is compiled from genotp-go using gomobile bind. To rebuild the native artifacts after updating genotp-go, see the genotp-mobile repository.

1
likes
0
points
11
downloads

Publisher

unverified uploader

Weekly Downloads

TOTP/HOTP one-time password plugin for Flutter, powered by genotp-go via gomobile. Works on Android and iOS with no network dependency.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on genotp_flutter

Packages that implement genotp_flutter