b64decode

Description

Returns a string that is base-64 decoded.

Syntax

b64decode <string>

b64decode <string>

  • Returns a string that is base-64 decoded

Examples

when RULE_INIT {
   set ::key [AES::key]
}
when HTTP_RESPONSE {
   set decrypted [HTTP::cookie "MyCookie"]
   HTTP::cookie remove "MyCookie"
   set encrypted [b64encode [AES::encrypt $::key $decrypted]]
   HTTP::cookie insert name "MyCookie" value $encrypted
}
when HTTP_REQUEST {
   set encrypted [HTTP::cookie "MyCookie"]
   HTTP::cookie remove "MyCookie"
   set decrypted [AES::decrypt $::key [b64decode $encrypted]]
   HTTP::cookie insert name "MyCookie" value $decrypted
}

Note: b64decode seems to trigger a runtime TCL error when decoding fails. See below for an example which uses catch to handle this.
Test decoding an invalid string
log local0. "[b64decode "\\a b c d"]"

LTM log output
01220001:3: TCL error: scratch_rule <RULE_INIT> - conversion error invoked from within "b64decode "\\a b c d""

Use catch to handle runtime errors when decoding a potentially invalid input string
# Try to base64 decode $string_b64encoded. Handle errors using catch.
#   Successful execution of b64decode by catch will return 0 and the output will be written to $string_b64decoded
if {[catch {b64decode $string_b64encoded} string_b64decoded] == 0 and $string_b64decoded ne ""}{
   # base64 decoding succeeded
} else {
   # base64 decoding failed
}