Base32Encoding

Namespace: Babel.Licensing Assembly: Babel.Licensing.dll

Converts between binary data and an base32-encoded string. This class cannot be inherited.

public sealed class Base32Encoding : IEncoding

Inheritance

objectBase32Encoding

Implements

IEncoding

Inherited Members

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Constructors

Base32Encoding()

public Base32Encoding()

Methods

CanDecode(string)

Determine if we can decode the given string.

public static bool CanDecode(string encoded)

Parameters

NameDescription

encoded string

The encoded string.

Returns

NameDescription

true if we can decode, false if not.

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Decode(string)

Decodes the given string to its byte representation.

public byte[] Decode(string encoded)

Parameters

NameDescription

encoded string

The encoded string.

Returns

NameDescription

The decoded string buffer.

Examples

// Encode and decoding using Base32Encoding
Base32Encoding base32 = new Base32Encoding();
byte[] data = Enumerable.Range(1, 10).Select(i => (byte)i).ToArray();

// Encode data byte[]
// 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA
string encoded = base32.Encode(data);

// encoded string
// BQAGACUAGYBQQEIB

// Decode encodes string 
byte[] decoded = base32.Decode(encoded);

// decoded byte[]
// 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA

Exceptions

NameDescription

Thrown when one or more required arguments are null.

Encode(byte[])

Encodes the given buffer.

public string Encode(byte[] bytes)

Parameters

NameDescription

bytes byte[]

The buffer.

Returns

NameDescription

The encoded string.

Examples

// Encode and decoding using Base32Encoding
Base32Encoding base32 = new Base32Encoding();
byte[] data = Enumerable.Range(1, 10).Select(i => (byte)i).ToArray();

// Encode data byte[]
// 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA
string encoded = base32.Encode(data);

// encoded string
// BQAGACUAGYBQQEIB

// Decode encodes string 
byte[] decoded = base32.Decode(encoded);

// decoded byte[]
// 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA

Exceptions

NameDescription

Thrown when one or more required arguments are null.

IsValidChar(char)

Query if the given character is a valid for encoding.

public bool IsValidChar(char ch)

Parameters

NameDescription

ch char

The input character.

Returns

NameDescription

true if valid character, false if not.

Examples

// Check if a character is valid Ascii85 symbol
Base32Encoding base32 = new Base32Encoding();

bool validBase32Char1 = base32.IsValidChar('-');
// validBase32Char1
// flase

bool validBase32Char2 = base32.IsValidChar('A');
// validBase32Char2
// true

Last updated