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)
}

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

SplashScreen Compat: consistent splash screens

Complete guide to set up fast Android CI/CD environment

Making Screens Adaptive to different screen sizes in the most easy way

ConcatAdapter/MergedAdapter with multiple UI types

A Comparison Between Java and Kotlin Collections APIs

Glass bottles and jugs organized by color

Jetpack Compose Ep:6 — Floating Action Button App

Exploring OCR Capabilities of ML Kit using Camera X

Going deep on Flows & Channels — Part 5: StateFlow

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.

More from Medium

How to create a simple coroutine in Kotlin, Android

A little about setContentView().

RecycleView Kotlin — Android Studio

Room Migrations — “Testing”