Namespace: Babel.Licensing
Assembly: Babel.Licensing.dll
Converts between binary data and an base32-encoded string. This class cannot be inherited.
Copy public sealed class Base32Encoding : IEncoding
Inheritance
object ← Base32Encoding
Implements
IEncoding
Inherited Members
object.GetType() , object.ToString() , object.Equals(object?) , object.Equals(object?, object?) , object.ReferenceEquals(object?, object?) , object.GetHashCode()
Constructors
Base32Encoding()
Copy public Base32Encoding ()
Methods
CanDecode(string)
Determine if we can decode the given string.
Copy public static bool CanDecode ( string encoded)
Parameters
Returns
Name Description true if we can decode, false if not.
Exceptions
Name Description Thrown when one or more required arguments are null.
Decode(string)
Decodes the given string to its byte representation.
Copy public byte [] Decode ( string encoded)
Parameters
Returns
Name Description The decoded string buffer.
Examples
C# VB
Copy // 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
Copy ' Encode and decoding using Base32Encoding
Dim base32 As New Base32Encoding()
Dim data As Byte() = Enumerable.Range(1, 10).[Select](Function(i) CByte(i)).ToArray()
' Encode data byte[]
' 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA
Dim encoded As String = base32.Encode(data)
' encoded string
' BQAGACUAGYBQQEIB
' Decode encodes string
Dim decoded As Byte() = base32.Decode(encoded)
' decoded byte[]
' 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA
Exceptions
Name Description Thrown when one or more required arguments are null.
Encode(byte[])
Encodes the given buffer.
Copy public string Encode ( byte [] bytes)
Parameters
Returns
Examples
C# VB
Copy // 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
Copy ' Encode and decoding using Base32Encoding
Dim base32 As New Base32Encoding()
Dim data As Byte() = Enumerable.Range(1, 10).[Select](Function(i) CByte(i)).ToArray()
' Encode data byte[]
' 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA
Dim encoded As String = base32.Encode(data)
' encoded string
' BQAGACUAGYBQQEIB
' Decode encodes string
Dim decoded As Byte() = base32.Decode(encoded)
' decoded byte[]
' 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xA
Exceptions
Name Description Thrown when one or more required arguments are null.
IsValidChar(char)
Query if the given character is a valid for encoding.
Copy public bool IsValidChar ( char ch)
Parameters
Returns
Name Description true if valid character, false if not.
Examples
C# VB
Copy // 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
Copy ' Check if a character is valid Ascii85 symbol
Dim base32 As New Base32Encoding()
Dim validBase32Char1 As Boolean = base32.IsValidChar("-"C)
' validBase32Char1
' flase
Dim validBase32Char2 As Boolean = base32.IsValidChar("A"C)
' validBase32Char2
' true
Last updated 3 months ago