Skip to content

Encode Method ​

Definition ​

  • Namespace: JASE.Crypto
  • Assembly: JASE.Crypto.dll

string Encode(ReadOnlySpan<byte> input) ​

csharp
string Encode(ReadOnlySpan<byte> input)

Encodes the specified byte array into a Base32 string using the RFC 4648 alphabet (A–Z, 2–7) and standard padding rules.

Parameters ​

NameDescription
inputThe binary data to encode. Must not be empty.

Returns ​

A Base32-encoded string whose length is always a multiple of 8 characters. Padding characters ('=') are appended when the input length is not a multiple of five bytes, following RFC 4648 section 6.

Remarks ​

This method performs a pure in-memory transformation from bytes to text using the standard Base32 alphabet: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 2 3 4 5 6 7.

The output size is calculated as: ceil(input.Length / 5) * 8. Because Base32 works in 5-byte (40-bit) groups, padding with '=' is used to complete the final 8-character block whenever necessary.

This implementation is allocation-efficient: it computes the exact output length and writes directly into a pre-sized character array, without temporary buffers or intermediate strings.