PRESENT

Common
JVM
JS
Native
1.0
PRESENT
(source)

Pad on encode, require padding on decode.

When encoding, the result is padded with '=' to reach an integral multiple of 4 symbols. When decoding, correctly padded input is required. The padding character '=' marks the end of the encoded data, and subsequent symbols are prohibited.

This represents the canonical form of Base64 encoding.

import kotlin.io.encoding.*
import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val format = HexFormat { upperCase = true; bytes.byteSeparator = " " }
val bytes = byteArrayOf(0xDE.toByte(), 0x2D, 0x02, 0xC0.toByte())

// The predefined Base64 instances are configured with PaddingOption.PRESENT.
// Hence, the same instance is returned.
val isSameInstance = Base64.Default.withPadding(Base64.PaddingOption.PRESENT) === Base64.Default
println("isSameInstance is ${isSameInstance}") // true

// PaddingOption.PRESENT pads on encode, and requires padded input on decode
println(Base64.Default.encode(bytes)) // 3i0CwA==
println(Base64.Default.decode("3i0CwA==").toHexString(format)) // DE 2D 02 C0
// PaddingOption.PRESENT requires the decode input to be properly padded
// Base64.Default.decode("3i0CwA") // will fail with IllegalArgumentException
//sampleEnd
}