Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

encrypt-string

  • Behavior: Takes a message string, a Base64-encoded secret key and an algorithm name and returns a Base64 encoded encrypted message. The only algorithm currently implemented is AES encryption in the GCM mode.
  • Return: A Base64 encoded sequence of bytes, structured as follows:
    • Byte 0: the length of the initialization vector (IV_LEN)
    • Bytes 1 to IV_LEN: the initialization vector, which is needed for AES decryption
    • Bytes IV_LEN+1 to end: the encrypted message bytes
  • Arguments: A message string, a Base64-encoded secret key, which should be 256 bits (32 bytes) for AES, and an algorithm name string, which should currently always be 'AES'.
  • Syntax: encrypt-string(message, key, algorithm)
  • Example: encrypt-string('abcdef', 'Vx1ZqYO06xSiYRoJNAqPtjXGAbjRS/lKqMukkoD0vEc=', 'AES') -> "DAqlxpaPUrTPsCnQ2yVoVM6xf7YqvN1LNA7jdp34NAb25yI="
  • Since: This function is available in CommCare 2.51 and later.
  • Click here for an example.

substring-before

  • Behavior: Takes two strings, a base string and a query string and returns the substring of the base string that precedes the first occurrence of the query string, or the empty string if the base string does not contain the query string
  • Return: A substring of the first argument
  • Arguments: A base string and a query string.
  • Syntax: substring-before(full_string, substring)
  • Example: substring-before('hello_there', '_there'). In conjunction with string-length, this can calculate the index of the 1st occurrence of a query string: string-length(substring-before(base_string, query_string))+1
  • Since: This function is available on CommCare 2.31 and later

...