UrlSafe
The "base64url" encoding specified by RFC 4648 section 5
, Base 64 Encoding with URL and Filename Safe Alphabet.
Uses "The URL and Filename safe Base 64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding, consisting of 'A'..'Z'
, 'a'..'z'
, '-'
and '_'
characters.
This instance is configured with the padding option set to PaddingOption.PRESENT. Use the withPadding function to create a new instance with a different padding option if necessary.
Encode operation does not add any line separator character. Decode operation throws if it encounters a character outside the base64url alphabet.
Since Kotlin
1.8Samples
import kotlin.io.encoding.*
import kotlin.test.*
fun main() {
//sampleStart
val encoded = Base64.UrlSafe.encode("Hello? :> ".encodeToByteArray())
println(encoded) // SGVsbG8_IDo-IA==
//sampleEnd
}