encodeBase64ToBase64Url
encodeBase64ToBase64Url
Function
encodeBase64ToBase64Url
FunctionThe encodeBase64ToBase64Url
function transforms a standard Base64-encoded string into a Base64URL-safe format, which is commonly used in web tokens, URLs, and other contexts where Base64 characters (+
, /
, =
) may be problematic.
Purpose
Use this function when you need to:
Convert a Base64-encoded value into a Base64URL-safe variant
Ensure compatibility with URL-safe systems such as JWT (JSON Web Tokens)
Pass encoded values in query strings or API endpoints
🔗 Specification: Base64URL Standard – base64.guru
Function Definition
Function Name
this.encodeBase64ToBase64Url
Type
function
Available In
Server-Side Variables
Returns
string
(Base64URL-encoded string)
Parameters
input
A valid Base64-encoded string
string
"YWJjKys="
Conversion Behavior
This function applies the following transformations:
+
-
/
_
=
(removed)
Example Usage
async function() {
let x = this.encodeBase64ToBase64Url("YWJjKys="); // Base64 of "abc++"
return x; // → "YWJjKys"
}
This converts the Base64 string "YWJjKys="
into a Base64URL-safe format by removing =
padding and replacing special characters.
Use Cases
Encode payloads or claims for JWT (JSON Web Token)
Safely pass encoded values in URLs or query parameters
Normalize Base64 data for systems that reject or mishandle special characters
Notes
The input must be a valid Base64-encoded string. This function does not encode raw values — it only converts Base64 → Base64URL.
For Base64 encoding of raw input, use native methods or pre-process before using this function.
The resulting output will contain only URL-safe characters.
Summary
this.encodeBase64ToBase64Url
allows you to convert standard Base64 strings into the Base64URL format required by web standards like JWT. This ensures compatibility in environments where Base64 special characters can cause issues.
Last updated
Was this helpful?