搜尋套件、儲存庫與 APP 分類

套件詳情v2.2.0

base32

Dart 的 Base32 編碼器和解碼器,主要用於一次性密碼金鑰。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
18.1萬
喜歡數
29
Pub 分數
160

安裝套件

flutter pub add base32

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個用於使用 Base32 算法對資料進行編碼和解碼的 Dart 套件,專為安全處理一次性密碼(OTP)金鑰而設計。支援 RFC 4648 定義的標準 Base32 編碼,確保跨平台相容性。此套件輕巧且高效,非常適合需要安全、人類可讀的二進位資料表示之應用程式。它可在所有主要平台無縫運作,包括 Android、iOS、Web、macOS、Windows 及 Linux。

適用情境

  • 生成OTP密鑰
  • 安全數據編碼
  • 跨平台令牌處理
  • 將二進制資料編碼為文字儲存
  • 與 Google Authenticator 等 OTP 應用的互操作性

主要特色

  • 符合 RFC 4648
  • 支援編碼與解碼
  • 輕量且快速
  • 跨平台相容性
  • OTP 結合的簡單 API

適合對象

  • 兩步驗證應用
  • 安全憑證儲存
  • 需要 Base32 的行動和 Web 應用程式
  • 開發人員使用OTP協議
  • 需要標準化文字編碼的應用程式

使用建議

  • 不適用於一般用途的加密
  • 需要手動處理密鑰安全
  • 僅限Base32,不支援其他編碼
  • 對格式錯誤的輸入沒有內建的錯誤恢復
  • 最好搭配其他安全措施使用

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Dart

dart-base32

Simple base32 encode/decode following RFC4648. Can handle base32 for OTP secrets also.

Features:

Getting Started

Pubspec

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

dependencies:
  base32: 2.1.3
import 'package:base32/base32.dart';

Start encoding/decoding ...

// Encode a hex string to base32
base32.encodeHexString('48656c6c6f21deadbeef'); // -> 'JBSWY3DPEHPK3PXP'

// base32 decoding to original string.
base32.decodeAsHexString("JBSWY3DPEHPK3PXP"); // -> '48656c6c6f21deadbeef'

API

base32.encode(List<int> byteList, {Encoding encoding = Encoding.standardRFC4648})

Generate and return a RFC4648 base32 string from a list of bytes.

  • byteList - (List<int>) A list of bytes representing your input.

Returns String representation of the encoded base32.

base32.encodeHexString(String hex, {Encoding encoding = Encoding.standardRFC4648})

Generate and return a RFC4648 base32 string from a hex string.

  • hexString - (String) A string of hex values intended to be converted to bytes and encoded.

Returns String representation of the encoded base32

Example: Encode a hex string.

base32.encodeHexString('48656c6c6f21deadbeef'); // -> 'JBSWY3DPEHPK3PXP'
base32.encodeString(String base32str, {Encoding encoding = Encoding.standardRFC4648})

Generate and return a RFC4648 base32 string from a plain string.

  • base32str - (String) A string intended to be converted to bytes and encoded.

Returns String representation of the encoded base32

Example: Encode a hex string.

base32.encodeString('foobar'); // -> 'MZXW6YTBOI======'
base32.decode(String base32, {Encoding encoding = Encoding.standardRFC4648})

Decodes a base32 string back to its original byte values.

  • base32 - (String) The base32 string you wish to decode.

Returns Uint8List of the decoded data.

Example: Decode a base32 string, then output it in hex format

import "package:convert/convert.dart"
var decoded = base32.decode("JBSWY3DPEHPK3PXP");
var decodedHex = hex.encode(decoded); // -> '48656c6c6f21deadbeef'
base32.decodeAsHexString(String base32, {Encoding encoding = Encoding.standardRFC4648})

Decodes a base32 string back to its original byte values in hex string format.

  • base32 - (String) The base32 string you wish to decode.

Returns String of the decoded data.

Example: Decode a base32 string to a hex string.

import "package:convert/convert.dart"
var decoded = base32.decodeAsHexString("JBSWY3DPEHPK3PXP"); // -> '48656c6c6f21deadbeef'
base32.decodeAsString(String base32, {Encoding encoding = Encoding.standardRFC4648})

Decodes a base32 string back to its original byte values.

  • base32 - (String) The base32 string you wish to decode.

Returns String of the decoded data.

Example: Decode a base32 string to a string.

var decoded = base32.decodeAsString("MZXW6YTBOI======"); // -> 'foobar'
enum Encoding

This is a list of supported variants and their different encodings.

  • StandardRFC4648 - the default standard encoding
    • ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
    • Padded with =
  • base32Hex
    • 0123456789ABCDEFGHIJKLMNOPQRSTUV
    • Padded with =
  • crockford
    • 0123456789ABCDEFGHJKMNPQRSTVWXYZ
    • Not Padded
  • z-base-32
    • ybndrfg8ejkmcpqxot1uwisza345h769
    • Not Padded
  • geohash
    • 0123456789bcdefghjkmnpqrstuvwxyz
    • Padded with =
  • NonStandardRFC4648 - Same as StandardRFC4648, but lowercase, not supported by the spec.
    • abcdefghijklmnopqrstuvwxyz234567
    • Padded with =

Testing

dart test/base32_test.dart

Changelog

See CHANGELOG.md

所屬分類

原始碼儲存庫

使用此套件的專案