API: base64
Source:
utils/base64.ts
Utility class for performing Base64 encoding and decoding of data. It handles conversion between JavaScript strings, JavaScript byte arrays (any[]), and the native Java byte arrays required by the underlying Base64Facade.
Usage
import { base64 } from "sdk/utils";
import { response } from "sdk/http";
response.println(base64.encode("admin:admin"));
response.println(base64.decode("YWRtaW46YWRtaW4="));
response.flush();
response.close();Classes
Base64
Utility class for performing Base64 encoding and decoding of data.
It handles conversion between JavaScript strings, JavaScript byte arrays (any[]),
and the native Java byte arrays required by the underlying Base64Facade.
Methods
encode
encode (input:string|any[]):stringBase64 encoding: Converts the input data (text or byte array) into a
standard Base64 encoded string representation.
@param input The data to encode, either as a string or a JavaScript byte array (any[]).
@returns The resulting Base64 encoded string.
encodeAsBytes
encodeAsBytes (input:string|any[]):any[]Base64 encoding: Converts the input data (text or byte array) into a
JavaScript byte array (any[]) containing the Base64 encoded representation.
@param input The data to encode, either as a string or a JavaScript byte array (any[]).
@returns The resulting byte array containing the Base64 encoded data.
encodeAsNativeBytes
encodeAsNativeBytes (input:string|any[]):any[]Base64 encoding: Converts the input data (text or byte array) into a
native Java byte array containing the Base64 encoded representation.
This method is generally for internal use.
@param input The data to encode, either as a string or a JavaScript byte array (any[]).
@returns The resulting native Java byte array containing the Base64 data.
decode
decode (input:string|any[]):any[]Base64 decoding: Converts a Base64 input (text or byte array) back into
the original raw byte array (JavaScript any[]).
@param input The Base64 data to decode, either as a string or a JavaScript byte array (any[]).
@returns The decoded raw byte array (any[]). Returns null if decoding fails or input is null.
decodeAsNativeBytes
decodeAsNativeBytes (input:string|any[]):any[]Base64 decoding: Converts a Base64 input (text or byte array) back into
the original native Java raw byte array. This method is generally for internal use.
@param input The Base64 data to decode, either as a string or a JavaScript byte array (any[]).
@returns The decoded native Java byte array.