Encode Method
Encode(ReadOnlySpan<Byte>)
Encode the byte collection into a string representation.
public string Encode(ReadOnlySpan<byte> data)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Byte> | data | The byte collection to encode. |
Returns
A string representation of data
.
Implements
Encode(ReadOnlySpan<Byte>, Span<Char>)
Encode the byte collection into encoded
.
public void Encode(ReadOnlySpan<byte> data, Span<char> encoded)
Parameters
Type | Name | Description |
---|---|---|
System.ReadOnlySpan<System.Byte> | data | The data to be encoded. |
System.Span<System.Char> | encoded | A System.Span<> to encode the data to. |
Implements
Remarks
When encoding sensitive data that should not be in an immutable object, this method gives you the ability to encode directly to memory.
The point of this method is to allow you to encode data to memory that you own. Therefore, you must allocate this memory before calling this method. The amount of memory required varies depending on the encoding.
For Base16 and ModHex, it is one character per four bits of information, so two characters per byte.
For Base32, it is more complicated. Each character hold five bits of data. Plus, you must account for padding at the end of the encoded data. There is a method to calculate the space needed called GetEncodedSize(Int32) that will tell you how many bytes you need.