분류, 패키지 및 저장소 검색

패키지 상세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 개

소스 저장소

이 패키지를 사용하는 프로젝트