WebEncoders Class

Contains utility APIs to assist with common encoding and decoding operations.

Namespace
Microsoft.AspNetCore.WebUtilities
Assemblies
  • Microsoft.AspNetCore.WebUtilities

Syntax

public class WebEncoders
class Microsoft.AspNetCore.WebUtilities.WebEncoders

Methods

Base64UrlDecode(System.String)

Decodes a base64url-encoded string.

Arguments:input (System.String) – The base64url-encoded input to decode.
Return type:System.Byte<System.Byte>[]
Returns:The base64url-decoded form of the input.
public static byte[] Base64UrlDecode(string input)
Base64UrlDecode(System.String, System.Int32, System.Char[], System.Int32, System.Int32)

Decodes a base64url-encoded <em>input</em> into a <code>byte[]</code>.

Arguments:
  • input (System.String) – A string containing the base64url-encoded input to decode.
  • offset (System.Int32) – The position in <em>input</em> at which decoding should begin.
  • buffer (System.Char<System.Char>[]) – Scratch buffer to hold the System.Chars to decode. Array must be large enough to hold <em>bufferOffset</em> and <em>count</em> characters as well as Base64 padding characters. Content is not preserved.
  • bufferOffset (System.Int32) – The offset into <em>buffer</em> at which to begin writing the System.Chars to decode.
  • count (System.Int32) – The number of characters in <em>input</em> to decode.
Return type:

System.Byte<System.Byte>[]

Returns:

The base64url-decoded form of the <em>input</em>.

public static byte[] Base64UrlDecode(string input, int offset, char[] buffer, int bufferOffset, int count)
Base64UrlDecode(System.String, System.Int32, System.Int32)

Decodes a base64url-encoded substring of a given string.

Arguments:
  • input (System.String) – A string containing the base64url-encoded input to decode.
  • offset (System.Int32) – The position in <em>input</em> at which decoding should begin.
  • count (System.Int32) – The number of characters in <em>input</em> to decode.
Return type:

System.Byte<System.Byte>[]

Returns:

The base64url-decoded form of the input.

public static byte[] Base64UrlDecode(string input, int offset, int count)
Base64UrlEncode(System.Byte[])

Encodes <em>input</em> using base64url encoding.

Arguments:input (System.Byte<System.Byte>[]) – The binary input to encode.
Return type:System.String
Returns:The base64url-encoded form of <em>input</em>.
public static string Base64UrlEncode(byte[] input)
Base64UrlEncode(System.Byte[], System.Int32, System.Char[], System.Int32, System.Int32)

Encodes <em>input</em> using base64url encoding.

Arguments:
  • input (System.Byte<System.Byte>[]) – The binary input to encode.
  • offset (System.Int32) – The offset into <em>input</em> at which to begin encoding.
  • output (System.Char<System.Char>[]) – Buffer to receive the base64url-encoded form of <em>input</em>. Array must be large enough to hold <em>outputOffset</em> characters and the full base64-encoded form of <em>input</em>, including padding characters.
  • outputOffset (System.Int32) – The offset into <em>output</em> at which to begin writing the base64url-encoded form of <em>input</em>.
  • count (System.Int32) – The number of <code>byte</code>s from <em>input</em> to encode.
Return type:

System.Int32

Returns:

The number of characters written to <em>output</em>, less any padding characters.

public static int Base64UrlEncode(byte[] input, int offset, char[] output, int outputOffset, int count)
Base64UrlEncode(System.Byte[], System.Int32, System.Int32)

Encodes <em>input</em> using base64url encoding.

Arguments:
  • input (System.Byte<System.Byte>[]) – The binary input to encode.
  • offset (System.Int32) – The offset into <em>input</em> at which to begin encoding.
  • count (System.Int32) – The number of bytes from <em>input</em> to encode.
Return type:

System.String

Returns:

The base64url-encoded form of <em>input</em>.

public static string Base64UrlEncode(byte[] input, int offset, int count)
GetArraySizeRequiredToDecode(System.Int32)

Gets the minimum <code>char[]</code> size required for decoding of <em>count</em> characters with the Microsoft.AspNetCore.WebUtilities.WebEncoders.Base64UrlDecode(System.String,System.Int32,System.Char[],System.Int32,System.Int32) method.

Arguments:count (System.Int32) – The number of characters to decode.
Return type:System.Int32
Returns:The minimum <code>char[]</code> size required for decoding of <em>count</em> characters.
public static int GetArraySizeRequiredToDecode(int count)
GetArraySizeRequiredToEncode(System.Int32)

Get the minimum output <code>char[]</code> size required for encoding <em>count</em> System.Bytes with the Microsoft.AspNetCore.WebUtilities.WebEncoders.Base64UrlEncode(System.Byte[],System.Int32,System.Char[],System.Int32,System.Int32) method.

Arguments:count (System.Int32) – The number of characters to encode.
Return type:System.Int32
Returns:The minimum output <code>char[]</code> size required for encoding <em>count</em> System.Bytes.
public static int GetArraySizeRequiredToEncode(int count)