Android Kotlin Base64 Encode/Decode

btnEncode?.setOnClickListener {
val
input = etText?.text.toString()
val byte = input.toByteArray(charset("UTF-8"))
val base64 = Base64.getEncoder().encodeToString(byte)
etBase64?.setText(base64)
}

btnDecode?.setOnClickListener {
val
input = etBase64?.text.toString()
val byte = Base64.getDecoder().decode(input)
val text = String(byte, charset("UTF-8"))
etText?.setText(text)
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin FOO

Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.