Encode/Decode Data Assertion

The Encode/Decode Data assertion is used to encode data to and from Base64 and URL Encoded formats.
gateway90
The
Encode/Decode Data
assertion is used to encode data to and from Base64 and URL Encoded formats.
  • For Base32/Base64:
    This assertion can encode variables of type String, Message, or X.509 Certificate into a String or Message Base32/Base64-encoded variable. It can decode a String or Message variable into a String, Message, or X.509 Certificate variable.
  • For Hex Encoding:
    This assertion supports hex (Base16) encoding/decoding.
  • For URL Encoding:
    This assertion supports encoding/decoding to/from a String or Message variable.
  • For Zip/Gzip Compression:
    This assertion supports compressing/decompressing to/from Zip and Gzip.
To see the results of the encoding or decoding, audit the output variable using the Add Audit Detail Assertion.
Encoding and decoding are performed only on the main (first) part of a Message variable. Other MIME parts can be decoded using the 'parts' variables, but cannot be the target of decoding. For example, use
${message.parts.2.body}
to decode the body from the second MIME part of the message. For more information about the 'parts' variables, see Transport Layer Context Variables.
Using the Assertion
  1. Do one of the following:
    • To add the assertion to the Policy Development window, see Add an Assertion.
    • To change the configuration of an existing assertion, proceed to step 2 below.
  2. Right-click the assertion in the policy window and select
    Encode/Decode Data Properties
    or double-click the assertion in the policy window. The assertion properties are displayed. (Note that depending on how the assertion is configured, it may appear in the policy as "
    Base64 Encode...
    ", "
    Base64 Decode...
    ", "
    URL Encode...
    ", or "
    URL Decode...
    ".)
  3. Configure the properties as follows:
    Setting
    Description
    Encode/Decode
    From the drop-down list, select the operation to perform:
    • Base32 Encode:
      Encodes any supported variable type (String, Message, X.509 Certificate) into a String or Message Base32 encoded variable.
    • Base32 Decode:
      Decodes a String or Message variable into a String, Message of any supported Content-Type, or X509 Certificate.
    • Base64 Encode:
      Encodes any supported variable type (String, Message, X.509 Certificate) into a String or Message Base64 encoded variable.
    • Base64 Decode:
      Decodes a String or Message variable into a String, Message of any supported Content-Type, or X509 Certificate.
    • Base16 (hex) Encode:
      Encodes using hex (Base16).
    • Base16 (hex) Decode:
      Decodes using hex (Base16).
    • URL Encode:
      Encodes to a text variable (String or Message).
    • URL Decode:
      Decodes from a text variable to a text variable.
    • Zip Compress:
      Compresses the input into a file named "contents.dat" within a ZIP archive. The ZIP archive is written to the target message variable.
    • Zip Decompress:
      Unzips the input. The first file in the archive (regardless of name) is decompressed and placed into the target message variable. 
    • GZIP Compress:
      Compresses a single input file in the gzip format.
    • GZIP Decompress:
      Decompresses a gzip file.
    Source Variable
    Specify the context variable that contains the input value, with or without the "${ }" wrapper. Multivalued context variables are not supported.
    Target Variable
    Specify the context variable that holds the output. If this variable does not already exist, it is created. As with the Source Variable, you may include the "${ }" wrapper but this is not necessary.
    Target Options
    Data Type
    Select whether the target variable is of type
    String
    ,
    Message
    , or
    X.509 Certificate
    . For more information about variable data types, see Set Context Variable Assertion.
    Content-Type
    Specify the Content-Type for the target variable. Available only when the data type is '
    Message
    '.
    Encode/Decode Options
    Character Encoding
    Enter the character encoding to use during encode/decode. These are the most common encodings:
    • ASCII: 
      Traditional 7-bit ASCII, bytes 0 (NUL) through 127 (DEL).
      Note:
      Bytes with values above 127 have no corresponding character in this encoding. For example, if you convert a binary file to characters and back using this encoding, it will be corrupted.
    • UTF-8:
      Superset of 7-bit ASCII that can represent arbitrary Unicode code points (using variable numbers of bytes per character). Bytes 0 through 127 are the same as ASCII. Bytes 128 through 255 are used to encode variable length Unicode characters with arbitrary code points (up to 6 bytes per character, for code points outside the basic multilingual plane).
      Note:
      Not all byte sequences express a valid UTF-8 encoding. For example, if you convert a binary file to characters and back using this encoding, it will be corrupted.
    • UTF-16:
      Superset of UCS-2. Modern variable-width Unicode format. This is the native character encoding format for Java (technically, a Java char is a single 16-bit UCS-2 code unit). Can represent any Unicode character, including those in the supplementary planes with code points above 65535.
    • Windows-1252:
      (also known as “Latin-1” or ISO-8859-1) Superset of 7-bit ASCII that can express some European language characters. This character set contains exactly 256 characters, with a one-to-one mapping between characters and bytes. This means you can convert a binary file to characters and back using this encoding without corruption.
    Less common encodings include:
    • UCS-2
      : Original fixed-width 16-bit (two byte) Unicode format, capable of representing Unicode code points from 0 to 65535. This encoding has been replaced by UTF-16.  Can only represent characters in the basic multilingual plane.
    • Cp437
      : Code page 437, the original IBM PC MS-DOS character set. It is also an 8-bit character set, so is binary transparent.
    The 
    Layer7 API Gateway
     is also capable of supporting other encodings, based on the JDK and operating system (see Software Gateway Specifications).
    Strict
    Select this option to scan the Base64 data for illegal Base64 characters. If any are found, the assertion fails.
    Clear this option to prevent the assertion from failing due to illegal Base64 characters.
    This option is available only when performing a '
    Base64 Decode
    '.
    Multiple lines
    Select this option to break the output into multiple lines during encoding.
    Clear this check box to render the output in a single line.
    Line break every
    X
    characters
    If the output is being broken into separate lines, specify where the line break should occur in the encoded Base64 data. The default is after every
    76
    characters.
  4. Click [
    OK
    ]
    when done.