How to encode and decode in Android Studio with Base64 encoder

Base64 is used for encoding a text(ASCII) to a binary stream(RFC 4648  RFC 2045).

Many PHP, HTML sites are using Base65  functions to encode images or data streams.

This is a simple example of using a Base64 encoder:

        String dataD = "hello";
        byte[] bytes = dataD.getBytes();
        dataD = new String(android.util.Base64.encode(bytes, Base64.DEFAULT));
        String decoded_message;
        byte[] str = dataD.getBytes();
        decoded_message = new String(android.util.Base64.decode(bytes, Base64.DEFAULT));

Leave a Reply

Your email address will not be published. Required fields are marked *