Sometimes need to encode / decode some data. As example sometimes need to encode some data, ...
Really simple way do it use Base64 Encoder, which has adding to Android SDK since API 18, This class contain methods for encoding the Base64 representation of binary data.
For work Base64 Encoder in android need to import
Output:
Really simple way do it use Base64 Encoder, which has adding to Android SDK since API 18, This class contain methods for encoding the Base64 representation of binary data.
For work Base64 Encoder in android need to import
- import android.util.Base64;
String testValue = "Hello, world!";
byte[] encodeValue = Base64.encode(testValue.getBytes(), Base64.DEFAULT);
byte[] decodeValue = Base64.decode(encodeValue, Base64.DEFAULT);
Log.d("TEST", "defaultValue = " + testValue);
Log.d("TEST", "encodeValue = " + new String(encodeValue));
Log.d("TEST", "decodeValue = " + new String(decodeValue));
Output:
- defaultValue = Hello, world!
- encodeValue = SGVsbG8sIHdvcmxkIQ==
- decodeValue = Hello, world!
Comments
Post a Comment