Base64

Base64 encoding/decoding in accordance with RFC 4648 section 4 and RFC 4648 section 5.

NOTE: All instances decode both Default.CHARS and UrlSafe.CHARS interchangeably; no special configuration is needed.

e.g.

val base64 = Base64.Builder {
    isLenient(enable = true)
    lineBreak(interval = 64)
    lineBreakReset(onFlush = true)
    encodeUrlSafe(enable = false)
    padEncoded(enable = true)
    backFillBuffers(enable = true)
}

val text = "Hello World!"
val bytes = text.encodeToByteArray()
val encoded = bytes.encodeToString(base64)
println(encoded) // SGVsbG8gV29ybGQh

// Alternatively, use the static implementation containing
// pre-configured settings, instead of creating your own.
var decoded = encoded.decodeToByteArray(Base64.Default).decodeToString()
assertEquals(text, decoded)
decoded = encoded.decodeToByteArray(Base64.UrlSafe).decodeToString()
assertEquals(text, decoded)

See also

Types

Link copied to clipboard
class Builder

A Builder

Link copied to clipboard
object Companion
Link copied to clipboard

Holder of a configuration for the Base64 encoder/decoder instance.

Link copied to clipboard

A static instance of EncoderDecoder configured with a Base64.Builder.lineBreak interval of 64, and remaining Base64.Builder DEFAULT values.

Link copied to clipboard

A static instance of EncoderDecoder configured with a Base64.Builder.lineBreak interval of 64, a Base64.Builder.encodeUrlSafe set to true, and remaining Base64.Builder DEFAULT values.

Functions

Link copied to clipboard
protected override fun name(): String
Link copied to clipboard
Link copied to clipboard