Base64Url.TryEncodeToUtf8 Method

Definition

Encodes the span of binary data into UTF-8 encoded chars represented as Base64Url.

C#
public static bool TryEncodeToUtf8(ReadOnlySpan<byte> source, Span<byte> destination, out int bytesWritten);

Parameters

source
ReadOnlySpan<Byte>

The input span which contains binary data that needs to be encoded.

destination
Span<Byte>

The output span which contains the result of the operation, i.e. the UTF-8 encoded text in Base64Url.

bytesWritten
Int32

When this method returns, contains the number of chars written into the output span. This can be used to slice the output for subsequent calls, if necessary. This parameter is treated as uninitialized.

Returns

true if bytes encoded successfully; false if destination is too small.

Remarks

This implementation of the base64url encoding omits the optional padding characters.

Applies to

Product Versions
.NET 8 (package-provided), 9, 10
.NET Standard 2.0 (package-provided), 2.1 (package-provided)