base32 1.1.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 94

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

Changelog #

v1.1.1

  • Fix broken pubspec.yaml

v1.1.0

  • Reimplemented Decode and Encode to fix issue #7
  • Decode now throws FormatException if you give it an invalide base32 string.
  • added encodeString() to pass in generic strings
  • added decodeAsString() to return straight string data
  • added decodeAsHexString() to return a hex format string directly
  • Use convert to do hex encoding/decoding.
  • Add a lot more tests, primarily from the RF4648 test cases.

v1.0.4 & v1.0.3 & v1.0.2

  • Some cleanup

v1.0.1

  • Enable 2.0.0 final support

v1.0.0

  • Merge pull request to fix List type and some readme formatting
  • This has been stable for years, moving to 1.0.0. Will release 1.0.0+1 when Dart 2.0 goes stable.

v0.1.2

  • Merge Pull Request to move most dependencies to dev_dependecies

v0.1.0 & v0.1.1wq

  • Updates for Dart 1.0 readiness.

v0.0.8

  • Fix crypto import in the test.

v0.0.7

  • Fix for typed_data name change. Thanks to the pull requestor for bringing it to my attention and fixing it.

v0.0.6

  • Fix for language changes.

v0.0.5

  • Fix for language changes.

v0.0.4

  • Fixes and changes for M3
  • New hex to byte converter.

v0.0.3

  • Made all functions static.

v0.0.2

  • Fixed unittest dependency

v0.0.1

  • Initial Documented Release

example/example.dart

import 'package:base32/base32.dart';

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

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

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  base32: ^1.1.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:base32/base32.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
87
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
94
Learn more about scoring.

We analyzed this package on Jun 5, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Health suggestions

Format lib/base32.dart.

Run dartfmt to format lib/base32.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <3.0.0
convert >=2.0.0 <3.0.0 2.1.1
Transitive dependencies
charcode 1.1.3
typed_data 1.1.6
Dev dependencies
pedantic ^1.0.0
test any