dw.crypto
Class Encoding
Object
dw.crypto.Encoding
Utility class which handles several common character encodings.
Constructor Summary
This class does not have a constructor, so you cannot create it directly.
Method Summary
static fromBase64(string : String) : Bytes
Decode the given string which represents a sequence of characters encoded in base-64 to a byte array.
static fromHex(string : String) : Bytes
Converts a String representing hexadecimal values into an array of bytes of those same values.
static fromURI(string : String) : String
Decodes a URL safe string into its original form.
static fromURI(string : String, encoding : String) : String
Decodes a URL safe string into its original form using the specified encoding.
static toBase64(bytes : Bytes) : String
Convert the given byte array to a string encoded in base-64.
static toHex(bytes : Bytes) : String
Converts an array of bytes into a string representing the hexadecimal values of each byte in order.
static toURI(string : String) : String
Encodes a string into its URL safe form according to the "application/x-www-form-urlencoded" encoding scheme using the default encoding.
static toURI(string : String, encoding : String) : String
Encodes a string into its URL safe form according to the "application/x-www-form-urlencoded" encoding scheme using the specified encoding.
Methods inherited from class Object
Method Detail
fromBase64
static fromBase64(string : String) : Bytes
Decode the given string which represents a sequence of characters encoded in base-64 to a byte array. Characters not in the base-64 alphabet are ignored. An exception is thrown if a null value is passed. Note: This decoding operation is limited to the maximum number of bytes that a Bytes object can hold. See Bytes.MAX_BYTES.
Parameters:
string - A string consisting of characters in base-64 alphabet to decode.
Returns:
The decoded array of bytes.

fromHex
static fromHex(string : String) : Bytes
Converts a String representing hexadecimal values into an array of bytes of those same values. The returned byte array will be half the length of the passed, as it takes two characters to represent any given byte. An exception is thrown if the passed string has an odd number of character or if any characters in the string are not valid hexadecimal characters. An exception is thrown if a null value is passed. Note: This decoding operation is limited to the maximum number of bytes that a Bytes object can hold. See Bytes.MAX_BYTES.
Parameters:
string - A string containing only hex characters to decode.
Returns:
The decoded array of bytes.

fromURI
static fromURI(string : String) : String
Decodes a URL safe string into its original form. Escaped characters are converted back to their original representation. An exception is thrown if URL decoding is unsuccessful or if null is passed.
Parameters:
string - The string to decode.
Returns:
The decoded string.

fromURI
static fromURI(string : String, encoding : String) : String
Decodes a URL safe string into its original form using the specified encoding. Escaped characters are converted back to their original representation. An exception is thrown if URL decoding is unsuccessful or if the specified encoding is unsupported or if null is passed for either argument.
Parameters:
string - The string to decode.
encoding - The name of a supported encoding.
Returns:
The decoded string.

toBase64
static toBase64(bytes : Bytes) : String
Convert the given byte array to a string encoded in base-64. This method does not chunk the data by adding line breaks. An exception is thrown if a null value is passed.
Parameters:
bytes - The array of bytes to encode.
Returns:
The encoded string containing only Base64 characters.

toHex
static toHex(bytes : Bytes) : String
Converts an array of bytes into a string representing the hexadecimal values of each byte in order. The returned string will be double the length of the passed array, as it takes two characters to represent any given byte. An exception is thrown if a null value is passed.
Parameters:
bytes - The array of bytes to encode.
Returns:
The encoded string containing only hex characters.

toURI
static toURI(string : String) : String
Encodes a string into its URL safe form according to the "application/x-www-form-urlencoded" encoding scheme using the default encoding. Unsafe characters are escaped. An exception is thrown if a null value is passed.
Parameters:
string - The string to encode.
Returns:
The encoded string.

toURI
static toURI(string : String, encoding : String) : String
Encodes a string into its URL safe form according to the "application/x-www-form-urlencoded" encoding scheme using the specified encoding. Unsafe characters are escaped. An exception is thrown if the specified encoding is unsupported. An exception is thrown if either argument is null.
Parameters:
string - The string to encode.
encoding - The name of a supported encoding.
Returns:
The encoded string.