Base64Url

Intro

Difference

SO Post diff b64 vs b64URL

The problem with Base64 is that it contains the characters +, /, and =, which have a reserved meaning in some filesystem names and URLs. So base64url solves this by replacing + with - and / with _. The trailing padding character = can be eliminated when not needed, but in a URL it would instead most likely be % URL encoded.

Code

Kotlin

val encoded = Base64.UrlSafe.encode("Hello? :> ".encodeToByteArray())
println(encoded) // SGVsbG8_IDo-IA== 

This class is not supposed to be inherited or instantiated by calling its constructor. However, predefined instances of this class are available for use. The companion object Base64.Default is the default instance of Base64. There are also Base64.UrlSafe and Base64.Mime instances. The padding option for all predefined instances is set to PaddingOption.PRESENT. New instances with different padding options can be created using the withPadding function.

kotlin lang | docs

base64.urlSafe

RFC

RFC 4648 | section 5

Tools

https://base64.guru/standards/base64url/encode