Base64

Common
JVM
JS
Native
1.8
@ExperimentalEncodingApi open class Base64
(source)

Provides Base64 encoding and decoding functionality.

This class is not supposed to be instantiated or inherited. However, predefined instances of this class are available for use. The companion object Base64.Default is the default instance of Base64. There are also Base64.UrlSafe and Base64.Mime instances.

Types

Common
JVM
JS
Native
1.0

Default

The "base64" encoding specified by RFC 4648 section 4, Base 64 Encoding.

companion object Default : Base64

Functions

Common
JVM
JS
Native
1.0

decode

Decodes symbols from the specified source array or its subrange. Returns a ByteArray containing the resulting bytes.

fun decode(
    source: ByteArray,
    startIndex: Int = 0,
    endIndex: Int = source.size
): ByteArray

Decodes symbols from the specified source char sequence or its substring. Returns a ByteArray containing the resulting bytes.

fun decode(
    source: CharSequence,
    startIndex: Int = 0,
    endIndex: Int = source.length
): ByteArray
Common
JVM
JS
Native
1.0

decodeIntoByteArray

Decodes symbols from the specified source array or its subrange and writes resulting bytes into the destination array. Returns the number of bytes written.

fun decodeIntoByteArray(
    source: ByteArray,
    destination: ByteArray,
    destinationOffset: Int = 0,
    startIndex: Int = 0,
    endIndex: Int = source.size
): Int

Decodes symbols from the specified source char sequence or its substring and writes resulting bytes into the destination array. Returns the number of bytes written.

fun decodeIntoByteArray(
    source: CharSequence,
    destination: ByteArray,
    destinationOffset: Int = 0,
    startIndex: Int = 0,
    endIndex: Int = source.length
): Int
Common
JVM
JS
Native
1.0

encode

Encodes bytes from the specified source array or its subrange. Returns a string with the resulting symbols.

fun encode(
    source: ByteArray,
    startIndex: Int = 0,
    endIndex: Int = source.size
): String
Common
JVM
JS
Native
1.0

encodeIntoByteArray

Encodes bytes from the specified source array or its subrange and writes resulting symbols into the destination array. Returns the number of symbols written.

fun encodeIntoByteArray(
    source: ByteArray,
    destination: ByteArray,
    destinationOffset: Int = 0,
    startIndex: Int = 0,
    endIndex: Int = source.size
): Int
Common
JVM
JS
Native
1.0

encodeToAppendable

Encodes bytes from the specified source array or its subrange and appends resulting symbols to the destination appendable. Returns the destination appendable.

fun <A : Appendable> encodeToAppendable(
    source: ByteArray,
    destination: A,
    startIndex: Int = 0,
    endIndex: Int = source.size
): A
Common
JVM
JS
Native
1.0

encodeToByteArray

Encodes bytes from the specified source array or its subrange. Returns a ByteArray containing the resulting symbols.

fun encodeToByteArray(
    source: ByteArray,
    startIndex: Int = 0,
    endIndex: Int = source.size
): ByteArray

Companion Object Properties

Common
JVM
JS
Native
1.0

Mime

The encoding specified by RFC 2045 section 6.8, Base64 Content-Transfer-Encoding.

val Mime: Base64
Common
JVM
JS
Native
1.0

UrlSafe

The "base64url" encoding specified by RFC 4648 section 5, Base 64 Encoding with URL and Filename Safe Alphabet.

val UrlSafe: Base64