ltm rule command b64decodeΒΆ

iRule(1)		      BIG-IP TMSH Manual		      iRule(1)



b64decode
       Returns a string that is base-64 decoded.

SYNOPSIS
       b64decode ANY_CHARS

DESCRIPTION
       Returns a string that is base-64 decoded.

RETURN VALUE
       b64decode 
	   Returns a string that is base-64 decoded

VALID DURING
       RULE_INIT

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  - 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
	}

HINTS
       Use catch to avoid issues with non b64encoded strings causing a TCL
       error and resetting your connection.

SEE ALSO
CHANGE LOG
       @BIGIP-9.0.0 --First introduced the command.  @BIGIP-11.1.0 --First
       introduced the command.



BIG-IP				  2017-01-31			      iRule(1)