Linx Main Linx Help

Base64Url encode and decode

I’m seeing more and more Base64Url encoded data being used, especially around JWT tokens. Linx supports Base64 functions in its Expressions but not Base64Url (yet). Luckily it is quite simple to do your own conversion with a Linx expression.

Base64 to Base64Url:
=Base64.Replace("/", "_").Replace("+", "-").TrimEnd('=')

Base64Url to Base64:
=Base64Url.Replace("_", "/").Replace("-", "+").PadRight(Base64Url.Length + (Base64Url.Length % 4), '=')

2 Likes

Also, If you need to decode a base64 encoded STR such as the Basic authentication credentials in HTTP requests, use the below expression:

= #base64EncodedString#.ToBytesFromBase64().ToString("UTF8")

The string YWRtaW46YWRtaW4= will result in admin:admin.