This topic describes the syntax and parameters of encoding and decoding functions. This topic also provides examples on how to use the functions.

Functions

Type Subtype Function Description
Encoding and decoding String str_encode Encodes a string by using a specified encoding format.
str_decode Decodes a string by using a specified encoding format.
Base64 base64_encoding Encodes data by using the Base64 algorithm.
base64_decoding Decodes data by using the Base64 algorithm.
HTML html_encoding Encodes data in the HTML format.
html_decoding Decodes HTML-encoded data.
URL url_encoding Encodes URL data.
url_decoding Decodes URL data.
Compression and decompression Gzip gzip_compress Compresses data and then encodes the data by using the Base64 algorithm.
gzip_decompress Decodes data by using the Base64 algorithm and then decompresses the data.
Zlib zlib_compress Compresses data and then encodes the data by using the Base64 algorithm.
zlib_decompress Decodes data by using the Base64 algorithm and then decompresses the data.
Encryption and decryption AES aes_encrypt Encrypts data by using the AES algorithm.
aes_decrypt Decrypts data by using the AES algorithm.
Hash algorithm MD5 md5_encoding Encodes data by using the MD5 algorithm.
SHA1 sha1_encoding Encodes data by using the SHA1 algorithm.

str_encode

The str_encode function is used to encode a string by using a specified encoding format.

  • Syntax
    str_encode(value, "utf8", errors="ignore"))
  • Parameters
    Parameter Type Required Description
    value Arbitrary (automatically converted to the string type) Yes The value that you want to encode.
    encoding String No The encoding format. Default value: utf8. ASCII is supported.
    errors String No The method that is used to process characters if the characters cannot be recognized based on the encoding format. Valid values:
    • ignore: The characters are not encoded. This is the default value.
    • strict: An error is reported, and the data of the log is discarded.
    • replace: The characters are replaced with question marks (?).
    • xmlcharrefreplace: The characters are replaced with the related XML characters.
  • Response

    An encoded string is returned.

  • Examples
    • Example 1
      Raw log:
      test: asewds
      Transformation rule:
      e_set("f1", str_decode(str_encode("hello", "utf8"), "utf8"))
      Result:
      test: asewds
      f1: hello
    • Example 2
      Raw log:
      f2: test test data
      Transformation rule:
      e_set("f1", str_encode(v("f2"), "ascii", errors="ignore"))
      Result:
      f1:test 
      f2:test test data
    • Example 3
      Raw log:
      f2: test test data
      Transformation rule:
      e_set("f1", str_encode(v("f2"), "ascii", errors="strict"))
      Result:
      An error is reported during execution. 
    • Example 4
      Raw log:
      f2: test test data
      Transformation rule:
      e_set("f1", str_encode(v("f2"), "ascii", errors="replace"))
      Result:
      f1:test ????
      f2:test test data
    • Example 5
      Raw log:
      f2: test test data
      Transformation rule:
      e_set("f1", str_encode(v("f2"), "ascii", errors="xmlcharrefreplace"))
      Result:
      f1:test 测试数据
      f2:test test data

str_decode

The str_decode function is used to decode an input value by using a specified encoding format.

  • Syntax
    str_decode(value, "utf8", errors="ignore"))
    Note The str_decode function can process only the data of the byte data type.
  • Parameters
    Parameter Type Required Description
    value Arbitrary (automatically converted to the string type) Yes The value that you want to decode.
    encoding Arbitrary (automatically converted to the string type) No The encoding format. Default value: utf8. ASCII is supported.
    errors Arbitrary (automatically converted to the string type) No The method that is used to process characters if the characters cannot be recognized based on the encoding format. Valid values:
    • ignore: The characters are not encoded. This is the default value.
    • strict: An error is reported, and the data of the log is discarded.
    • replace: The characters are replaced with question marks (?).
    • xmlcharrefreplace: The characters are replaced with the related XML characters.
  • Response

    A decoded value is returned.

  • Examples
    Raw log:
    test: asewds
    Transformation rule:
    e_set("encoding", str_decode(b'\xe4\xbd\xa0\xe5\xa5\xbd', "utf8",'strict'))
    Result:
    test: asewds
    encoding: hello

base64_encoding

The base64_encoding function is used to encode data by using the Base64 algorithm.

  • Syntax
    base64_encoding(Value,format=None)
  • Parameters
    Parameter Type Required Description
    Value String Yes The value that you want to encode.
    format String No The Base64 encoding scheme. Valid values: RFC 3548 and RFC 4648. Default value: RFC 3548.
  • Response

    A Base64-encoded string is returned.

  • Example
    • Raw log entry:
      str_en : data to be encoded
    • Transformation rule:
      e_set("str_base64",base64_encoding(v("str_en")))
    • Result:
      str_en : data to be encoded
      str_base64 : ZGF0YSB0byBiZSBlbmNvZGVk

base64_decoding

The base64_decoding function is used to decode data by using the Base64 algorithm.

  • Syntax
    base64_decoding(Value,format=None)
  • Parameters
    Parameter Type Required Description
    Value String Yes The value that you want to decode.
    format String No The Base64 decoding scheme. Valid values: RFC 3548 and RFC 4648. Default value: RFC 3548.
    Note The Base64 decoding scheme in RFC 4648 uses an equal sign (=) to convert a decoded value to a multiple of 4 bytes.
  • Response

    A Base64-decoded string is returned.

  • Example
    • Raw log entry:
      str_de: ZGF0YSB0byBiZSBlbmNvZGVk
    • Transformation rule:
      e_set("str_de_base64",base64_decoding(v("str_de")))
    • Result:
      str_de: ZGF0YSB0byBiZSBlbmNvZGVk
      str_de_base64: data to be encoded

html_encoding

The html_encoding function is used to encode data in the HTML format.

  • Syntax
    html_encoding(Value)
  • Parameters
    Parameter Type Required Description
    Value String Yes The value that you want to encode.
  • Response

    An HTML-encoded string is returned.

  • Example
    • Raw log entry:
      str : <img class="size-medium wp-image-113" style="margin-left: 15px;" title="su1" src="http://aliyundoc.com/wp-content/uploads/2008/10/su1-300x194.jpg" alt="" width="300" height="194" />
    • Transformation rule:
      e_set("str_html_en",html_encoding(v("str")))
    • Result:
      str : <img class="size-medium wp-image-113" style="margin-left: 15px;" title="su1" src="http://aliyundoc.com/wp-content/uploads/2008/10/su1-300x194.jpg" alt="" width="300" height="194" />
      str_html_en : &lt;img class=&quot;size-medium wp-image-113&quot; style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot; src=&quot;http://aliyundoc.com/wp-content/uploads/2008/10/su1-300x194.jpg&quot; alt=&quot;&quot; width=&quot;300&quot; height=&quot;194&quot; /&gt;

html_decoding

The html_decoding function is used to decode HTML-encoded data.

  • Syntax
    html_decoding(Value)
  • Parameters
    Parameter Type Required Description
    Value String Yes The value that you want to decode.
  • Response

    An HTML-decoded string is returned.

  • Example
    • Raw log entry:
      str : &lt;img class=&quot;size-medium wp-image-113&quot; style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot; src=&quot;http://aliyundoc.com/wp-content/uploads/2008/10/su1-300x194.jpg&quot; alt=&quot;&quot; width=&quot;300&quot; height=&quot;194&quot; /&gt;
    • Transformation rule:
      e_set("str_html_de",html_decoding(v("str")))
    • Result:
      str : &lt;img class=&quot;size-medium wp-image-113&quot; style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot; src=&quot;http://aliyundoc.com/wp-content/uploads/2008/10/su1-300x194.jpg&quot; alt=&quot;&quot; width=&quot;300&quot; height=&quot;194&quot; /&gt;
      str_html_de : <img class="size-medium wp-image-113" style="margin-left: 15px;" title="su1" src="http://aliyundoc.com/wp-content/uploads/2008/10/su1-300x194.jpg" alt="" width="300" height="194" />

url_encoding

The url_encoding function is used to encode URL data.

  • Syntax
    url_encoding(Value)
  • Parameters
    Parameter Type Required Description
    Value String Yes The value that you want to encode.
  • Response

    A URL-encoded string is returned.

  • Example
    • Raw log entry:
      content : https://www.example.org/hello/asdah
    • Transformation rule:
      e_set("url",url_encoding(v("content")))
    • Result:
      content : https://www.example.org/hello/asdah
      url: https%3A%2F%www.example.org%2FHello%2Fasdah

url_decoding

The url_decoding function is used to decode URL data.

  • Syntax
    url_decoding(Value)
  • Parameters
    Parameter Type Required Description
    Value String Yes The value that you want to decode.
  • Response

    A URL-decoded string is returned.

  • Example
    • Raw log entry:
      content : https%3A%2F%www.example.org%2FHello%2Fasdah
    • Transformation rule:
      e_set("URL",url_decoding(v("content")))
    • Result:
      content : https%3A%2F%www.example.org%2FHello%2Fasdah
      URL : https://www.example.org/hello/asdah

gzip_compress

The gzip_compress function is used to compress data and then encode the data by using the Base64 algorithm.

  • Syntax
    gzip_compress(data, compresslevel=6, to_format="base64", encoding="utf-8")
  • Parameters
    Parameter Type Required Description
    data Arbitrary Yes The data that you want to compress.
    compresslevel Int No The compression level. Valid values: 0 to 9. Default value: 6.
    • 1: Data is compressed at the highest speed but with the lowest compression ratio.
    • 9: Data is compressed at the lowest speed but with the highest compression ratio.
    • 0: Data is not compressed.
    to_format String No The encoding format for the compressed data. Only the Base64 algorithm is supported.
    encoding String No The encoding format for the raw data. Default value: utf-8. For more information about other encoding formats, see Standard encoding formats.
  • Response

    Compressed data that is encoded in Base64 is returned.

  • Example
    • Raw log entry:
      content: I always look forward to my holidays whether I travel or stay at home.
    • Transformation rule:
      e_set("base64_encode_gzip_compress",gzip_compress(v("content"),to_format="base64"))
    • Result:
      content: I always look forward to my holidays whether I travel or stay at home.
      base64_encode_gzip_compress: H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA

gzip_decompress

The gizp_decompress function is used to decode data by using the Base64 algorithm and then decompress the data.

  • Syntax
    gzip_decompress(data, from_format="base64", encoding="utf-8")
  • Parameters
    Parameter Type Required Description
    data Arbitrary Yes The data that you want to decompress.
    from_format String No The encoding format for the decompressed data. Only the Base64 algorithm is supported.
    encoding String No The encoding format for the raw data. Default value: utf-8. For more information about other encoding formats, see Standard encoding formats.
  • Response

    Decompressed and Base64-decoded data is returned.

  • Example
    • Raw log entry:
      content: H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA
    • Transformation rule:
      e_set("gzip_decompress",gzip_decompress(v("content"),from_fmat="base64"))
    • Result:
      content: H4sIAA8JXl4C/xXK0QmAMAwFwFXeBO7RMQKNREx5kAZDtle/7wbES3rDyRsnoyQmklgNo1/ztzJN08BAhjzqYGCnNCS/tPR4AcgrnWVGAAAA
      gzip_decompress: I always look forward to my holidays whether I travel or stay at home.

zlib_compress

The zlib_compress function is used to compress data and then encode the data by using the Base64 algorithm.

  • Syntax
    zlib_compress(data, compresslevel=6, to_format="base64", encoding="utf-8")
  • Parameters
    Parameter Type Required Description
    data Arbitrary Yes The data that you want to compress.
    compresslevel Int No The compression level. Valid values: 0 to 9. Default value: 6.
    • 1: Data is compressed at the highest speed but with the lowest compression ratio.
    • 9: Data is compressed at the lowest speed but with the highest compression ratio.
    • 0: Data is not compressed.
    to_format String No The encoding format for the compressed data. Only the Base64 algorithm is supported.
    encoding String No The encoding format for the raw data. Default value: utf-8. For more information about other encoding formats, see Standard encoding formats.
  • Response

    Compressed and Base64-encoded data is returned.

  • Example
    • Raw log entry:
      content: I always look forward to my holidays whether I travel or stay at home.
    • Transformation rule:
      e_set("zlib_compress", zlib_compress(v("content"), to_format="base64"))
    • Result:
      zlib_compress: "eJwVytEJgDAMBcBV3gTu0TECjURMeZAGQ7ZXv+8GxEt6w8kbJ6MkJpJYDaNf87cyTdPAQIY86mBgpzQkv7T0eAGNshln"
      content: "I always look forward to my holidays whether I travel or stay at home."

zlib_decompress

The zlib_decompress function is used to decode data by using the Base64 algorithm and then decompress the data.

  • Syntax
    zlib_decompress(data, from_format="base64", encoding="utf-8")
  • Parameters
    Parameter Type Required Description
    data Arbitrary Yes The data that you want to decompress.
    from_format String No The encoding format for the decompressed data. Only the Base64 algorithm is supported.
    encoding String No The encoding format. Default value: utf-8. For more information about other encoding formats, see Standard encoding formats.
  • Response

    Decompressed and Base64-decoded data is returned.

  • Example
    • Raw log entry:
      content: "eJwVytEJgDAMBcBV3gTu0TECjURMeZAGQ7ZXv+8GxEt6w8kbJ6MkJpJYDaNf87cyTdPAQIY86mBgpzQkv7T0eAGNshln"
    • Transformation rule:
      e_set("zlib_decompress", zlib_decompress(v("content"), from_format="base64"))
    • Result:
      content: "eJwVytEJgDAMBcBV3gTu0TECjURMeZAGQ7ZXv+8GxEt6w8kbJ6MkJpJYDaNf87cyTdPAQIY86mBgpzQkv7T0eAGNshln"
      zlib_decompress: "I always look forward to my holidays whether I travel or stay at home."

aes_encrypt

The aes_encrypt function is used to encrypt data by using the AES algorithm. The Advanced Encryption Standard (AES) algorithm is the most common symmetric encryption algorithm. To ensure data security, you can use the AES algorithm to encrypt data.

  • Syntax
    aes_encrypt(data,key,mode,pad_style,pad_block,input_format,input_encoding,output_format,iv)
  • Parameters
    Parameter Type Required Description
    data String Yes The data that you want to encrypt.
    key String Yes The key that you want to use to encrypt data.
    mode String No The encryption mode of the AES algorithm.
    • CBC (default): Cipher Block Chaining
    • ECB: Electronic Codebook Book
    • CFB: Cipher Feedback
    • OFB: Output Feedback
    • CTR: Counter
    • OPENPGP
    pad_style String No The padding mode. Default value: pkcs7. Valid values: iso7816, x923, and pkcs7.
    input_format String No The format of characters. Default value: raw. Valid values:
    • raw: bytes
    • hex: hexadecimal
    • Base64: Base64 encoding format
    input_encoding String No The encoding format. This parameter is required only if you set the input_format parameter to raw. The encoding format. Default value: uft-8.
    output_format String No The format of characters. Default value: hex. Valid values:
    • raw: bytes
    • hex: hexadecimal
    • Base64: Base64 encoding format
    iv Bytes No The offset that is used for encryption.
  • Response

    The string that is encrypted from a value by using the AES algorithm is returned.

  • Examples
    • Example 1
      • Raw log entry:
        "test": "aliyuntest"
      • Transformation rule:
        e_set('result',aes_encrypt(v("test"), "qwertyuiopasdfgd", iv=b"xxywosjdapdiawdk", output_format="base64"))
      • Result:
        "result": "gXIqu0cBBtZHQxJBK8GLeA=="
    • Example 2
      • Raw log entry:
        "test": "aliyuntest"
      • Transformation rule:
        e_set('result',aes_encrypt(v("test"), "qwertyuiopasdfgh", iv=b"ywisnjaduaqibdqi", mode="OFB"))
      • Result:
        "result":  "5cac3e9e1c42f713dc6d"

aes_decrypt

The aes_decrypt function is used to decrypt encrypted data by using the AES algorithm.

  • Syntax
    aes_decrypt(data,key,mode,pad_style,input_format,input_encoding,output_format,iv,output_encoding)
  • Parameters
    Parameter Type Required Description
    data String Yes The data that you want to decrypt.
    key String Yes The key that you want to use to decrypt data.
    mode String No The decryption mode of the AES algorithm.
    • CBC (default): Cipher Block Chaining
    • ECB: Electronic Codebook Book
    • CFB: Cipher Feedback
    • OFB: Output Feedback
    • CTR: Counter
    • OPENPGP
    pad_style String No The padding mode. Default value: pkcs7. Valid values: iso7816, x923, and pkcs7.
    input_format String No The format of characters. Default value: hex. Valid values:
    • raw: bytes
    • hex: hexadecimal
    • Base64: Base64 encoding format
    input_encoding String No The encoding format. This parameter is required only if you set the input_format parameter to raw. The encoding format. Default value: uft-8.
    output_format String No The format of characters. Default value: raw. Valid values:
    • raw: bytes
    • hex: hexadecimal
    • Base64: Base64 encoding format
    iv Bytes No The offset that is used for decryption.
    output_encoding String No The encoding format. Default value: None.
  • Response

    The string that is decrypted from a value by using the AES algorithm is returned.

  • Examples
    • Example 1
      • Raw log entry:
        "test": "gXIqu0cBBtZHQxJBK8GLeA=="
      • Transformation rule:
        e_set('result', aes_decrypt(v("test"), "qwertyuiopasdfgd", iv=b"xxywosjdapdiawdk", input_format="base64"))
      • Result:
        "result": "aliyuntest"
    • Example 2
      • Raw log entry:
        "test": "5cac3e9e1c42f713dc6d"
      • Transformation rule:
           e_set('result', aes_decrypt(v("test"), "qwertyuiopasdfgh", iv=b"ywisnjaduaqibdqi", mode="OFB"))
      • Result:
        "result": "aliyuntest"

md5_encoding

The md5_encoding function is used to encode data by using the MD5 algorithm.

  • Syntax
    md5_encoding(Value,format="hex")
  • Parameters
    Parameter Type Required Description
    Value String Yes The value that you want to encode.
    format String No Valid values: binary and hex. Default value: hex.
  • Response

    An MD5 hash value is returned.

  • Examples
    • Example 1
      • Raw log entry:
        str : GeeksforGeeks
      • Transformation rule:
        e_set("str_md5_en",md5_encoding(v("str")))
      • Result:
        str : GeeksforGeeks
        str_md5_en : f1e069787ece74531d112559945c6871
    • Example 2
      • Raw log entry:
        str : GeeksforGeeks
      • Transformation rule:
        e_set("str_md5_en",base64_encoding(md5_encoding(v("str"), format="binary")))
      • Result:
        str : GeeksforGeeks
        str_md5_en : 8eBpeH7OdFMdESVZlFxocQ==

sha1_encoding

The sha1_encoding function is used to encode data by using the SHA1 algorithm.

  • Syntax
    sha1_encoding(Value,format=None)
  • Parameters
    Parameter Type Required Description
    Value String Yes The value that you want to encode.
    format String No The SHA algorithm. Valid values: SHA1, SHA224, SHA256, SHA384, and SHA512. Default value: SHA1.
  • Response

    A SHA1-encoded string is returned.

  • Example
    • Raw log entry:
      str : GeeksforGeeks
    • Transformation rule:
      e_set("str_sha1",sha1_encoding(v("str")))
      e_set("str_sha512",sha1_encoding(v("str"),format='SHA512'))
      e_set("str_sha224",sha1_encoding(v("str"),format='SHA224'))
      e_set("str_sha384",sha1_encoding(v("str"),format='SHA384'))
      e_set("str_sha256",sha1_encoding(v("str"),format='SHA256'))
    • Result:
      str : GeeksforGeeks
      str_sha1 : 4175a37afd561152fb60c305d4fa6026b7e79856
      str_sha512 : 0d8fb9370a5bf7b892be4865cdf8b658a82209624e33ed71cae353b0df254a75db63d1baa35ad99f26f1b399c31f3c666a7fc67ecef3bdcdb7d60e8ada90b722
      str_sha224 : 173994f309f727ca939bb185086cd7b36e66141c9e52ba0bdcfd145d
      str_sha384 : d1e67b8819b009ec7929933b6fc1928dd64b5df31bcde6381b9d3f90488d253240490460c0a5a1a873da8236c12ef9b3
      str_sha256 : f6071725e7ddeb434fb6b32b8ec4a2b14dd7db0d785347b2fb48f9975126178f