Base64

class Base64(config: Base64.Config) : EncoderDecoder<Base64.Config> (source)

Base64 encoding/decoding in accordance with RFC 4648 section 4 & 5 (Default & UrlSafe)

https://www.ietf.org/rfc/rfc4648.html#section-4 https://www.ietf.org/rfc/rfc4648.html#section-5

Decodes both Default and UrlSafe, while encoding to UrlSafe can be configured via the Base64.Config.

e.g.

val base64 = Base64 {
    isLenient = true
    lineBreakInterval = 64
    encodeToUrlSafe = false
    padEncoded = true
}

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

// Alternatively, use the static implementaton instead of
// configuring your own settings.
val decoded = encoded.decodeToByteArray(Base64.Default).decodeToString()
assertEquals(text, decoded)

See also

EncoderDecoder
Decoder.Companion.decodeToByteArray
Decoder.Companion.decodeToByteArrayOrNull
Encoder.Companion.encodeToString
Encoder.Companion.encodeToCharArray
Encoder.Companion.encodeToByteArray

Constructors

Link copied to clipboard
constructor(config: Base64.Config)

Types

Link copied to clipboard
class Config : EncoderDecoder.Config

Configuration for Base64 encoding/decoding.

Link copied to clipboard
object Default : EncoderDecoder<Base64.Config>

Doubles as a static implementation with default settings and a lineBreakInterval of 64.

Link copied to clipboard
object UrlSafe : EncoderDecoder<Base64.Config>

Doubles as a static implementation with default settings and a lineBreakInterval of 64.

Functions

Link copied to clipboard
protected open override fun name(): String
Link copied to clipboard
protected open override fun newDecoderFeedProtected(out: Decoder.OutFeed): Decoder.Feed<Base64.Config>
Link copied to clipboard
protected open override fun newEncoderFeedProtected(out: Encoder.OutFeed): Encoder.Feed<Base64.Config>