Android 中是否有用于字符串的 Base-64 解码器和编码器?
这是如何使用的示例Base64
类来编码和解码简单的字符串值。
// String to be encoded with Base64
String text = "Test";
// Sending side
byte[] data = null;
try {
data = text.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
String base64 = Base64.encodeToString(data, Base64.DEFAULT);
// Receiving side
byte[] data1 = Base64.decode(base64, Base64.DEFAULT);
String text1 = null;
try {
text1 = new String(data1, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
此摘录可以包含在 Android 活动中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)