Encoding
Returns the hexadecimal string that represents the data.
Encodings.ToHex(ReadOnlySpan<byte> data)
data
has a length of 0.The data could not be converted to hex.
Returns a byte array from a hexadecimal string. Common separator characters are ignored by default.
Encodings.FromHex(string hex, string ignoreChars = ":- ")
hex
is null.hex
has a length of 0.Unable to parse the hex string.
Returns the Base64 string representing the data. Choose one variant (e.g. Base64URL for file names/URLs) and only ever use that variant.
Encodings.ToBase64(ReadOnlySpan<byte> data, Base64Variant variant = Base64Variant.Original)
data
has a length of 0.The data could not be converted to Base64.
Returns a byte array from a Base64 string. The variant must match the one used for encoding.
Encodings.FromBase64(string base64, Base64Variant variant = Base64Variant.Original, string ignoreChars = " ")
base64
is null.base64
has a length of 0.Unable to parse the Base64 string.
public enum Base64Variant
{
Original = 1,
OriginalNoPadding = 3,
Url = 5,
UrlNoPadding = 7
}
Do NOT support multiple variants of Base64 in your application (e.g. Base64 with and without padding). This can lead to vulnerabilities.
Unlike in the .NET library, these functions run in constant time to avoid potential side-channel attacks. Furthermore, the Base64 implementation should be more resistant to malleability attacks.
Base64 has a better compression rate than hex. However, they tend to be used for different purposes. For instance, hex is often used for test vectors and encoding hashes, whereas Base64 is more commonly used for encoding keys.
Last modified 10d ago