kotlin decode base64
To decode a Base64 string in Kotlin, you can use the Base64
class from the java.util
package. Here are the steps to decode a Base64 string in Kotlin:
Import the necessary classes:
kotlin import java.util.Base64
Create a
Base64.Decoder
object:kotlin val decoder = Base64.getDecoder()
Convert the Base64 string to a byte array:
kotlin val base64String = "SGVsbG8gd29ybGQh" val base64Bytes = base64String.toByteArray()
Decode the byte array using the
decode
method of theBase64.Decoder
object:kotlin val decodedBytes = decoder.decode(base64Bytes)
Convert the decoded byte array to a string:
kotlin val decodedString = String(decodedBytes)
That's it! The decodedString
variable now contains the decoded string from the Base64 input.