Encode and Decode Actions
  • 02 Jun 2022
  • 1 Minute to read
  • Dark
    Light

Encode and Decode Actions

  • Dark
    Light

Article Summary

Encode & Decode Actions

decodeBase64ToBytes

Decode Base64 encoded data to a byte array.

Property

Value

Description

data*

expression, variable

data to decode

returnVariable

expression, variable

name of the variable to be assigned to the return value

userXML = loadFileAsXML("users/user.dsml")
photoBytes = decodeBase64ToBytes(userXML.photo[0]);
saveToFile("user.jpg", photoBytes)

decodeBase64ToString

Decode Base64 encoded data to a string.

Property

Value

Description

data*

expression, variable

data to decode

charset

text, expression, variable

character set encoding for converting bytes to characters(default: UTF-8)

returnVariable

expression, variable

name of the variable to be assigned to the return value

authHeader = {Authorization: "Basic dXNlcm5hbWU6cGFzc3dvcmQ="}
b64Credentials = splitString(authHeader.Authorization, "/\s+/")
textCredentials = decodeBase64ToString(b64Credentials[2], "UTF-8")
splitCredentials = splitString(textCredentials, ":", 2)
username = splitCredentials[0]
password = splitCredentials[1]

decodeHexToBytes

Decode Ascii Hex encoded data to a byte array.

Property

Value

Description

data*

expression, variable

data to decode

returnVariable

expression, variable

name of the variable to be assigned to the return value

md5hashBytes = decodeHexToBytes(md5hash)

decodeHexToString

Decode Ascii Hex encoded data to a string.

Property

Value

Description

data*

expression, variable

data to decode

charset

text, expression, variable

character set encoding for converting bytes to characters(default: UTF-8)

returnVariable

expression, variable

name of the variable to be assigned to the return value

string = decodeHexToString(hexstring)

encodeBytesToBase64

Encode a byte array as Base64.

Property

Value

Description

data*

expression, variable

data to encode

breakLines

boolean, expression, variable

break base64 output into lines (default: false)

returnVariable

expression, variable

name of the variable to be assigned to the return value

ldapRecord = getLDAPRecord(ldapConnection,"cn=jdoe,ou=people,o=data","photo")
photoBase64 = encodeBytesToBase64(ldapRecord.photo,true)

encodeBytesToHex

Encode a byte array as Ascii Hex.

Property

Value

Description

data*

expression, variable

data to encode

returnVariable

expression, variable

name of the variable to be assigned to the return value

md5hash = encodeBytesToHex(md5hashBytes)

encodeStringToBase64

Encode a string as Base64.

Property

Value

Description

data*

expression, variable

data to encode

charset

text, expression, variable

character set encoding for converting characters to bytes(default: UTF-8)

breakLines

boolean, expression, variable

break base64 output into lines (default: false)

returnVariable

expression, variable

name of the variable to be assigned to the return value

xml = <foo><bar/></foo>
base64XML = encodeStringToBase64(xml.toXMLString())
setRecordFieldValue(record, "someBase64Field", base64XML)

encodeStringToHex

Encode a string as Ascii Hex.

Property

Value

Description

data*

expression, variable

data to encode

charset

text, expression, variable

character set encoding for converting characters to bytes(default: UTF-8)

returnVariable

expression, variable

name of the variable to be assigned to the return value

hex = decodeHexToString(string)

Was this article helpful?

What's Next