Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

CryptoEncoding Methods

Daniel Linsley edited this page May 15, 2017 · 2 revisions

Encoding

Methods to encode / decode data between different encodings.

CryptoEncoding.base64Decode

Base64 decoder. Builds string from byte data using UTF-8 encoding.

Signature

String CryptoEncoding.base64Decode(String b64data)

Parameters

Name Type Description
b64data String Base64 data to decode.

CryptoEncoding.base64Encode

Base64 encoder. Returns Base64 encoded UTF-8 bytes of the string data.

Signature

String CryptoEncoding.base64Encode(String data)

Parameters

Name Type Description
data String String data to encode.

CryptoEncoding.base64toMime

Base64 to MimeAttachment. Builds a MimeAttachment object from binary data.

This is useful if you have data from a webservice that is Base64 encoded and would like to:

  • Attach it to an email
  • Create a ResourceElement from it
  • Write it to the filesystem

Signature

MimeAttachment CryptoEncoding.base64ToMime(String b64data, String mimeType, String fileName)

Parameters

Name Type Description
b64data String Base64 encoded data.
mimeType String Mime type of the data. Ex: text/plain, application/xml, application/pdf
fileName String Filename of MimeAttachment if it were written to a filesystem

CryptoEncoding.base64toHex

Base64 to Hex Encoder. Binary conversion.

Signature

String CryptoEncoding.base64toHex(String b64data)

Parameters

Name Type Description
b64data String Base64 data to encode as Hex

CryptoEncoding.binaryConcatBase64

Decodes two Base64 encoded strings. Concatenates the byte arrays, returns the result as a Base64 String.

Useful for prepending ciphertext with an initialization vector.

Signature

String CryptoEncoding.binaryConcatBase64(String b64data1, String b64data2)

Parameters

Name Type Description
b64data1 String Base64 data
b64data2 String Base64 data to append

CryptoEncoding.getLengthBase64

Decodes a Base64 encoded string. Returns the length of data in bytes.

To get the length of a Hex string, use hexToBase64 and then this method.

Signature

Number CryptoEncoding.getLengthBase64(String b64data)

Parameters

Name Type Description
b64data String Base64 data

CryptoEncoding.getSubsetBase64

Returns a subset of bytes from a Base64 encoded string.

Useful for extracting an initialization vector that has been prepended to ciphertext.

Signature

String CryptoEncoding.getSubsetBase64(String b64data, Number start, Number length)

Parameters

Name Type Description
b64data String Base64 data
start Number Starting byte index to get subset of data (inclusive). Starts at 0
length Number Number of bytes to return. Must be 1 or greater.

CryptoEncoding.hexToBase64

Hex to Base64 encoder

Signature

String CryptoEncoding.hexToBase64(String hex)

Parameters

Name Type Description
hex String Hex data to convert to Base64

CryptoEncoding.mimeToBase64

Extracts data from a MimeAttachment object as Base64 encoded string.

Signature

String CryptoEncoding.mimeToBase64(MimeAttachment mime)

Parameters

Name Type Description
mime MimeAttachment