For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

NetSnoopy's avatar
NetSnoopy
Icon for Cirrus rankCirrus
Apr 13, 2017

Base64 ( b64encode) vs Base64Url Encode and Base64UrlDecode

Hello all,

The last days i had a lot of problems to build a iRule that contains strings with Base64UrlEncode. URLencode means replace "+" to "-" and "/" to "_" and cut trailing "=".

  1. URI::encode is not URL encode
  2. first do a b64encode
  3. replace string with "[string map [list + - \/ _ = "" ] $var]"

In a Irule shows like:

set var_b64_url "[string map [list + - \/ _ = "" ] [b64encode "$var"]"

But i do not have a solution to do this revers for Base64UrlDecode

my idea is

set var_b64 "[string map [list - + _ \/ ] $var_b64_url"]"
set var_decode "[b64decode $var_b64]"

But i don't have a solution for the trailing "=" ?

Cheers, NetSnoopy

1 Reply

  • Hi, it is an interesting your request, so I'll not ask what you are intending and just try a statement.

    set var_b64 "[string map [list - + _ \/ ] $var_b64_url]"
    if { [string length $var_b64] % 4 != 0 } {
        append var_b64 [string repeat = [expr {4 - [string length $var_b64] % 4}]]
    }
    

    I hope it helps you.