encodeToByteArray

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

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

If the size of the source byte string or its subrange is not an integral multiple of 3, the result is padded with '=' to an integral multiple of 4 symbols.

Each resulting symbol occupies one byte in the returned byte array.

Use encode to get the output in string form.

Return

a ByteArray with the resulting symbols.

Parameters

source

the byte string to encode bytes from.

startIndex

the beginning (inclusive) of the subrange to encode, 0 by default.

endIndex

the end (exclusive) of the subrange to encode, size of the source byte string by default.

Throws

when startIndex or endIndex is out of range of source byte string indices.

when startIndex > endIndex.