Encoding as Base64 in Java

前端 未结 17 2500
失恋的感觉
失恋的感觉 2020-11-21 13:44

I need to encode some data in the Base64 encoding in Java. How do I do that? What is the name of the class that provides a Base64 encoder?


I tried to use the <

17条回答
  •  情话喂你
    2020-11-21 13:48

    On Android, use the static methods of the android.util.Base64 utility class. The referenced documentation says that the Base64 class was added in API level 8 (Android 2.2 (Froyo)).

    import android.util.Base64;
    
    byte[] encodedBytes = Base64.encode("Test".getBytes());
    Log.d("tag", "encodedBytes " + new String(encodedBytes));
    
    byte[] decodedBytes = Base64.decode(encodedBytes);
    Log.d("tag", "decodedBytes " + new String(decodedBytes));
    

提交回复
热议问题