Skip to content

Base64

Spice
import "std/text/base64";

Functions

encodeBase64

Spice
public f<String> encodeBase64(string input, bool padding = true)

Encode the given raw string to base64, using the standard alphabet

Parameters

Name Type Description
input string String to encode, excluding its null terminator
padding bool Pad the output with '=' to a multiple of 4 chars or not (default: true)

Returns: String — Base64 representation of the input

encodeBase64

Spice
public f<String> encodeBase64(const String& input, bool padding = true)

Encode the given string to base64, using the standard alphabet

Parameters

Name Type Description
input const String& String to encode. All of its bytes are encoded, including null bytes
padding bool Pad the output with '=' to a multiple of 4 chars or not (default: true)

Returns: String — Base64 representation of the input

encodeBase64

Spice
public f<String> encodeBase64(const byte[] input, unsigned long length, bool padding = true)

Encode the given raw bytes to base64, using the standard alphabet

Parameters

Name Type Description
input const byte[] Bytes to encode
length unsigned long Number of bytes to encode
padding bool Pad the output with '=' to a multiple of 4 chars or not (default: true)

Returns: String — Base64 representation of the input

encodeBase64Url

Spice
public f<String> encodeBase64Url(string input, bool padding = true)

Encode the given raw string to base64, using the URL- and filename-safe alphabet

Parameters

Name Type Description
input string String to encode, excluding its null terminator
padding bool Pad the output with '=' to a multiple of 4 chars or not (default: true)

Returns: String — Base64 representation of the input

encodeBase64Url

Spice
public f<String> encodeBase64Url(const String& input, bool padding = true)

Encode the given string to base64, using the URL- and filename-safe alphabet

Parameters

Name Type Description
input const String& String to encode. All of its bytes are encoded, including null bytes
padding bool Pad the output with '=' to a multiple of 4 chars or not (default: true)

Returns: String — Base64 representation of the input

encodeBase64Url

Spice
public f<String> encodeBase64Url(const byte[] input, unsigned long length, bool padding = true)

Encode the given raw bytes to base64, using the URL- and filename-safe alphabet

Parameters

Name Type Description
input const byte[] Bytes to encode
length unsigned long Number of bytes to encode
padding bool Pad the output with '=' to a multiple of 4 chars or not (default: true)

Returns: String — Base64 representation of the input

decodeBase64

Spice
public f<Result<String>> decodeBase64(string input)

Decode the given base64 string, that uses the standard alphabet

Parameters

Name Type Description
input string Base64 string, with or without padding

Returns: Result<String> — Decoded bytes, or an error if the input is no valid base64

decodeBase64

Spice
public f<Result<String>> decodeBase64(const String& input)

Decode the given base64 string, that uses the standard alphabet. The padding is optional, but if present, it has to be complete. Chars outside of the alphabet, including whitespace and line breaks, are rejected.

Parameters

Name Type Description
input const String& Base64 string, with or without padding

Returns: Result<String> — Decoded bytes, or an error if the input is no valid base64

decodeBase64Url

Spice
public f<Result<String>> decodeBase64Url(string input)

Decode the given base64 string, that uses the URL- and filename-safe alphabet

Parameters

Name Type Description
input string Base64 string, with or without padding

Returns: Result<String> — Decoded bytes, or an error if the input is no valid base64

decodeBase64Url

Spice
public f<Result<String>> decodeBase64Url(const String& input)

Decode the given base64 string, that uses the URL- and filename-safe alphabet. The padding is optional, but if present, it has to be complete. Chars outside of the alphabet, including whitespace and line breaks, are rejected.

Parameters

Name Type Description
input const String& Base64 string, with or without padding

Returns: Result<String> — Decoded bytes, or an error if the input is no valid base64