Base64 encode and decode example code

后端 未结 12 939
遥遥无期
遥遥无期 2020-11-22 15:00

Does anyone know how to decode and encode a string in Base64 using the Base64. I am using the following code, but it\'s not working.

String source = \"passwo         


        
12条回答
  •  悲&欢浪女
    2020-11-22 15:42

    If you are using Kotlin than use like this

    For Encode

    val password = "Here Your String"
    val data = password.toByteArray(charset("UTF-8"))
    val base64 = Base64.encodeToString(data, Base64.DEFAULT)
    

    For Decode

    val datasd = Base64.decode(base64, Base64.DEFAULT)
    val text = String(datasd, charset("UTF-8"))
    

提交回复
热议问题