-
Notifications
You must be signed in to change notification settings - Fork 6
CryptoEncoding Methods
Methods to encode / decode data between different encodings.
Base64 decoder. Builds string from byte data using UTF-8 encoding.
String
CryptoEncoding.base64Decode(String b64data)
Name | Type | Description |
---|---|---|
b64data | String | Base64 data to decode. |
Base64 encoder. Returns Base64 encoded UTF-8 bytes of the string data.
String
CryptoEncoding.base64Encode(String data)
Name | Type | Description |
---|---|---|
data | String | String data to encode. |
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
MimeAttachment
CryptoEncoding.base64ToMime(String b64data, String mimeType, String fileName)
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 |
Base64 to Hex Encoder. Binary conversion.
String
CryptoEncoding.base64toHex(String b64data)
Name | Type | Description |
---|---|---|
b64data | String | Base64 data to encode as Hex |
Decodes two Base64 encoded strings. Concatenates the byte arrays, returns the result as a Base64 String.
Useful for prepending ciphertext with an initialization vector.
String
CryptoEncoding.binaryConcatBase64(String b64data1, String b64data2)
Name | Type | Description |
---|---|---|
b64data1 | String | Base64 data |
b64data2 | String | Base64 data to append |
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.
Number
CryptoEncoding.getLengthBase64(String b64data)
Name | Type | Description |
---|---|---|
b64data | String | Base64 data |
Returns a subset of bytes from a Base64 encoded string.
Useful for extracting an initialization vector that has been prepended to ciphertext.
String
CryptoEncoding.getSubsetBase64(String b64data, Number start, Number length)
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. |
Hex to Base64 encoder
String
CryptoEncoding.hexToBase64(String hex)
Name | Type | Description |
---|---|---|
hex | String | Hex data to convert to Base64 |
Extracts data from a MimeAttachment object as Base64 encoded string.
String
CryptoEncoding.mimeToBase64(MimeAttachment mime)
Name | Type | Description |
---|---|---|
mime | MimeAttachment |