- scala – encodeToString is not a member of Base64? – Stack Overflow
- convert a byte array to string – Stack Overflow
- How to convert byte array to string in Scala? (includehelp.com)
- java.nio.charset.StandardCharsets Scala Example (programcreek.com)
import java.util.Base64 import java.nio.charset.StandardCharsets val plainText: String = "abcdefg" val encoded: String = Base64.getEncoder.encodeToString(plainText.getBytes("UTF-8")) val decoded: Array[Byte] = Base64.getDecoder.decode(encoded) val str1 = new String(decoded) val str2 = new String(decoded, StandardCharsets.UTF_8)
output
plainText: String = abcdefg encoded: String = YWJjZGVmZw== decoded: Array[Byte] = Array(97, 98, 99, 100, 101, 102, 103) str1: String = abcdefg str2: String = abcdefg