Base64
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)Content copied to clipboard
See also
Encoder Decoder
Decoder. Companion. decode To Byte Array
Decoder. Companion. decode To Byte Array Or Null
Encoder. Companion. encode To String
Encoder. Companion. encode To Char Array
Encoder. Companion. encode To Byte Array
Types
Functions
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>