我想检查字符串是否为Base64编码格式,是否在安卓应用程序中。如果它是在Base64中,那么我需要解码它,并在解码后显示内容。我已经使用了Base 64 encode and decode example code和How to check whether the string is base64 encoded or not的答案,但问题是如何将Base64-regex与读取nfc标签后获得的字符串进行比较/验证。谢谢!
发布于 2016-02-25 14:51:14
现在回答这个问题可能太晚了,但如果你还在寻找这个问题,那么这可能会有所帮助。
if (org.apache.commons.codec.binary.Base64.isArrayByteBase64(base64String.getBytes())) {
try{
chatTitle = new String(Base64.decode(base64String, Base64.DEFAULT), "UTF-8");
} catch (Exception e) {}catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
org.apache.commons.codec.binary.Base64
是安卓系统的默认配置
发布于 2016-10-13 16:22:17
试一试
private boolean IsBase64Encoded(String value)
{
try {
byte[] decodedString = Base64.decode(value, Base64.DEFAULT);
BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
return true;
} catch (Exception e) {
return false;
}
}
https://stackoverflow.com/questions/32182249
复制相似问题