base32 1.1.1

Dart native js
Flutter Android iOS web

Base32 Encoder and Decoder for Dart, primarily used for One Time Password secrets.

Build Status

dart-base32 #

[![Join the chat at https://gitter.im/Daegalus/dart-base32](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Daegalus/dart-base32?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

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: 1.1.1
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) #

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) #

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) #

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) #

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) #

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) #

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'

Testing #

dart test/base32_test.dart

Changelog #

See CHANGELOG.md

2
likes
95
pub points
88%
popularity

Publisher

yuli.dev

Base32 Encoder and Decoder for Dart, primarily used for One Time Password secrets.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE.txt)

Dependencies

convert

More

Packages that depend on base32