Skip to content

Base32 Class

Provides methods for encoding and decoding data using Base32 and Base32hex formats as defined in RFC 4648. Supports optional padding and ignores padding characters during decoding.

C#
public static class Base32

Inheritance System.Object → Base32

Methods

Base32.Decode(ReadOnlySpan<char>) Method

Decodes a Base32-encoded string into a byte array. Ignores any '=' padding characters at the end of the input.

C#
public static byte[] Decode(System.ReadOnlySpan<char> input);

Parameters

input System.ReadOnlySpan<System.Char>

The Base32 string to decode (may include padding '=').

Returns

System.Byte[]
A byte array containing the original binary data.

Exceptions

System.ArgumentException
Thrown if the input contains invalid Base32 characters.

Base32.DecodeHex(ReadOnlySpan<char>) Method

Decodes a Base32hex-encoded string into a byte array. Ignores any '=' padding characters at the end of the input.

C#
public static byte[] DecodeHex(System.ReadOnlySpan<char> input);

Parameters

input System.ReadOnlySpan<System.Char>

The Base32hex string to decode (may include padding '=').

Returns

System.Byte[]
A byte array containing the original binary data.

Exceptions

System.ArgumentException
Thrown if the input contains invalid Base32hex characters.

Base32.Encode(ReadOnlySpan<byte>, bool) Method

Encodes the specified binary data into a Base32 string using the standard RFC 4648 alphabet (A-Z, 2-7).

C#
public static string Encode(System.ReadOnlySpan<byte> input, bool padding=true);

Parameters

input System.ReadOnlySpan<System.Byte>

The binary data to encode.

padding System.Boolean

true to include '=' characters to pad the output string to a multiple of 8 characters; false to omit padding.

Returns

System.String
A Base32-encoded string representation of the input data. If padding is true, the result length is always a multiple of 8 by adding '=' characters as needed.

Base32.EncodeHex(ReadOnlySpan<byte>, bool) Method

Encodes the specified binary data into a Base32hex string using the extended hexadecimal alphabet (0-9, A-V).

C#
public static string EncodeHex(System.ReadOnlySpan<byte> input, bool padding=true);

Parameters

input System.ReadOnlySpan<System.Byte>

The binary data to encode.

padding System.Boolean

true to include '=' characters to pad the output string to a multiple of 8 characters; false to omit padding.

Returns

System.String
A Base32hex-encoded string representation of the input data. If padding is true, the result length is always a multiple of 8 by adding '=' characters as needed.