カテゴリー・パッケージ・リポジトリを検索

パッケージ詳細v3.2.1

otp

RFC6238 時間ベースのワンタイムパスワード / Google Authenticator ライブラリ

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
8.7万
いいね数
204
Pub ポイント
160

パッケージをインストール

flutter pub add otp

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

RFC 6238 時間ベースのワンタイムパスワード(TOTP)アルゴリズムを実装したDartライブラリで、Google Authenticatorやその他のTOTP互換アプリと互換性があります。二要素認証(2FA)に使用する安全で時限的な認証コードを提供します。Android、iOS、Web、macOS、Windows、Linuxなど複数のプラットフォームでOTPの生成および検証が可能です。Flutterアプリケーションに2FAを最小限の設定で統合するのに最適です。

用途

  • モバイルアプリにおける二要素認証
  • 2FAを備えたセキュアなログインシステム
  • Google Authenticator との統合
  • 時間制限付きアクセスコードの生成
  • ユーザー アカウントの確認
  • バックアップコードの生成

主な機能

  • RFC 6238準拠のTOTP実装
  • クロスプラットフォーム対応
  • シンプルなOTPの生成と検証
  • カスタムタイムステップおよび桁数をサポート
  • 認証アプリと互換性があります
  • 軽量で依存関係なし

適している対象

  • 2FAを必要とするアプリ
  • 認証サービス
  • セキュリティを重視したアプリケーション
  • セキュアなログインフローを構築する開発者
  • 既存の TOTP システムとの統合

注意事項

  • 適切な時刻同期が必要です
  • QRコードの生成に対応していません
  • 組み込みのユーザーインターフェースなし
  • 秘密鍵のストレージの手動処理
  • 長期的なトークン保存には適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

MAJOR BEHAVIOR CHANGE IN 3.1.0: Explanation of Changes from 3.0 to 3.1

Dart

dart-otp

RFC4226/RFC6238 One-Time Password / Google Authenticator Library

Features:

Getting Started

Pubspec

pub.dartlang.org: (you can use 'any' instead of a version if you just want the latest always)

dependencies:
  otp: 3.2.0
import 'package:otp/otp.dart';

Start generating tokens.

// Generate TOTP code. (String versin of function incase of leading 0)
OTP.generateTOTPCodeString("JBSWY3DPEHPK3PXP", 1362302550000); // -> '505548'

// Generate HOTP Code.
OTP.generateHOTPCodeString("JBSWY3DPEHPK3PXP", 7); // -> '006676'

API

Notes

This library does not support any other secret input other than Base32. It is what is used standard most places, and by Google Authenticator. If your secrets are not Base32 forms, please use my Base32 library (the one I use as a dependency for this library) or any other base32 library to encode your secret before passing it into the functions. All generate functions force decode of Base32.

Global Settings

useTOTPPaddingForHOTP (bool, default: false) Uses the TOTP padding method for handling secrets bigger or smaller than the mandatory sizes for SHA256/SHA512. This is needed as HOTP does not have an official method of using SHA256 or SHA512 in the RFC spec and most libraries don't pad HOTP for use with SHA256 or SHA512. (examples: otplib and speakeasy from Node.js)

If you enable this, it will use the same padding as TOTP (repeating the secret to the right length) but might cause incompatibilies with other libraries. I am defaulting to no padding, as this is the predominant behavior I am finding for HOTP.

OTP.generateTOTPCode(String secret, int currentTime, {int length: 6, int interval: 30, Algorithm algorithm: Algorithm.SHA256, bool isGoogle: false})

Generate a code for the provided secret and time.

  • secret - (String) A Base32 String.
  • currentTime - (int) The current time in milliseconds.
  • length - (int) The length of the resulting code.
  • interval - (int) Refresh interval to get a new code.
  • algorithm - (Algorithm) Hashing method.
  • isGoogle - (bool) flag to turn off secret padding for Google Auth.

Returns an int code. Does not preserve leading zeros.

OTP.generateTOTPCodeString(String secret, int currentTime, {int length: 6, int interval: 30, Algorithm algorithm: Algorithm.SHA256, bool isGoogle: false})

Generate a code for the provided secret and time.

  • secret - (String) A Base32 String.
  • currentTime - (int) The current time in milliseconds.
  • length - (int) The length of the resulting code.
  • interval - (int) Refresh interval to get a new code.
  • algorithm - (Algorithm) Hashing method.
  • isGoogle - (bool) flag to turn off secret padding for Google Auth.

Returns an String code. Preserves leading zeros.

OTP.generateHOTPCode(String secret, int counter, {int length: 6})

Generate a code for the provided secret and time.

  • secret - (String) A Base32 String.
  • counter - (int) An int counter.
  • length - (int) the length of the resulting code.

Returns an int code. Does not preserve leading zeros

OTP.generateHOTPCodeString(String secret, int counter, {int length: 6})

Generate a code for the provided secret and time.

  • secret - (String) A Base32 String.
  • counter - (int) An int counter.
  • length - (int) the length of the resulting code.

Returns an String code. Preserves leading zeros

OTP.constantTimeVerification(final String code, final String othercode)

!DISCLAIMER! I can only get this to be within 1 millisecond between different codes and same codes. I have yet to get them to be equal. but 1 millisecond should be an OK room for error though.

Compares 2 codes in constant time to minimize risk of timing attacks.

  • code - (String) A Base32 String.
  • othercode - (String) A Base32 String.

Returns an bool if they match or not.

OTP.remainingSeconds({int interval = 30})

This will return the remaining seconds based on the lastUsedTime variable, that is only set when using generateTOTP* functions.

  • interval - (int) The interval you are using for your codes, defaults to the standard 30 seconds.

Returns an int of the remaining seconds.

Testing

pub run test

Release notes

See CHANGELOG.md

カテゴリー

依存関係

依存関係一覧 3 件

ソースリポジトリ

このパッケージを使用しているプロジェクト