public class EncoderDecoder {
public EncoderDecoder(){
}
public String encodeString(String s) {
byte[] data = new byte[0];
try {
data = s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} finally {
String base64Encoded = Base64.encodeToString(data, Base64.DEFAULT);
return base64Encoded;
}
}
public String decodeString(String encoded) {
byte[] dataDec = Base64.decode(encoded, Base64.DEFAULT);
String decodedString = "";
try {
decodedString = new String(dataDec, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} finally {
return decodedString;
}
}
}
A class that uses base 64 to encode and decode strings.
#base64 #decode #encode #encrypt #java #android
#cesarnog
#base64 #decode #encode #encrypt #java #android
#cesarnog
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.