Skip to content

Latest commit

 

History

History
195 lines (140 loc) · 7.26 KB

File metadata and controls

195 lines (140 loc) · 7.26 KB

Hashlib Codecs

plugin version test codecov likes pub points popularity dart support dependencies

This library contains implementations of fast and error resilient codecs in pure Dart.

Depencencies

This package has NO dependency.

Features

Binary (Base-2)

Type Available
Class Base2Codec
Methods fromBinary, toBinary

Available codecs:

  • standard: 01 (default)

Octal (Base-8)

Type Available
Class Base8Codec
Methods fromOctal, toOctal

Available codecs:

  • standard: 012345678 (default)

Hexadecimal (Base-16)

Type Available
Class Base16Codec
Methods fromHex, toHex

Available codecs:

  • upper: 0123456789ABCDEF (default)
  • lower: 0123456789abcdef

Base-32

Supports conversion without padding

Type Available
Class Base32Codec
Methods fromBase32, toBase32

Available codecs:

  • standard (RFC-4648): ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 (default)
  • lowercase: abcdefghijklmnopqrstuvwxyz234567
  • hex: 0123456789ABCDEFGHIJKLMNOPQRSTUV
  • hexLower: 0123456789abcdefghijklmnopqrstuv
  • crockford: 0123456789bcdefghjkmnpqrstuvwxyz
  • z: ybndrfg8ejkmcpqxot1uwisza345h769
  • wordSafe: 23456789CFGHJMPQRVWXcfghjmpqrvwx

Base-64

Supports conversion without padding, and
the URL/Filename-safe Base64 conversion.

Type Available
Class Base64Codec
Methods fromBase64, toBase64

Available codecs:

  • standard (RFC-4648): ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ (default)
  • urlSafe: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_
  • bcrypt: ./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

UTF-8

Type Available
Class UTF8Codec
Methods fromUtf8, toUtf8

Available codecs:

BigInt

Supports both the Big-Endian and Little-Endian conversion

Type Available
Class BigIntCodec
Methods fromBigInt, toBigInt

Available codecs:

  • msbFirst: treats the input bytes in big-endian order
  • lsbFirst: treats the input bytes in little-endian order

Modular Crypt Format (PHC String Format)

Encoding and Decoding of Hash algorithm output according to the PHC string format specification.

Type Available
Class CryptFormat
Constant crypt
Methods toCrypt, fromCrypt

ByteCollector

A container for digest bytes produced by a hash or encoding function. Available methods:

Method Description
bytes Raw bytes as Uint8List
length Length of the bytes
buffer The byte buffer backing the data
toString() String representation (hexadecimal)
hex([upper]) Hexadecimal string (optionally uppercase)
binary() Binary string representation
octal() Octal string representation
base32({upper, padding}) Base32 encoding (with case and padding options)
base64({urlSafe, padding}) Base64 encoding (with URL-safe and padding options)
bigInt({endian}) Interprets the bytes as a BigInt (endian selectable)
number([bitLength, endian]) Reads an unsigned integer of specified bit-length
ascii() Decodes bytes as an ASCII string
utf8() Decodes bytes as a UTF-8 string
to(encoding) Decodes bytes with a given Dart Encoding
isEqual(other) Compares the bytes with another list, buffer, or hex string

Getting Started

The following import will give you access to all of the algorithms in this package.

import 'package:hashlib_codecs/hashlib_codecs.dart';

Check the API Reference for details.

Usage

Examples can be found inside the example folder.

import 'package:hashlib_codecs/hashlib_codecs.dart';

void main() {
  var inp = [0x3, 0xF1];
  print("input => $inp");
  print('');

  print("binary => ${toBinary(inp)}");
  print('');

  print("octal => ${toOctal(inp)}");
  print('');

  print("hexadecimal => ${toHex(inp)}");
  print("hexadecimal (uppercase) => ${toHex(inp, upper: true)}");
  print('');

  print("base32 => ${toBase32(inp)}");
  print("base32 (lowercase) => ${toBase32(inp, lower: true)}");
  print("base32 (no padding) => ${toBase32(inp, padding: false)}");
  print("base32 (hex) => ${toBase32(inp, codec: Base32Codec.hex)}");
  print("base32 (z-base-32) => ${toBase32(inp, codec: Base32Codec.z)}");
  print("base32 (geohash) => ${toBase32(inp, codec: Base32Codec.geohash)}");
  print("base32 (crockford) => ${toBase32(inp, codec: Base32Codec.crockford)}");
  print("base32 (word-safe) => ${toBase32(inp, codec: Base32Codec.wordSafe)}");
  print('');

  print("base64 => ${toBase64(inp)}");
  print("base64url => ${toBase64(inp, url: true)}");
  print("base64 (no padding) => ${toBase64(inp, padding: false)}");
  print("bcrypt => ${toBase64(inp, codec: Base64Codec.bcrypt)}");
  print('');
}