您的位置:首页 > 移动开发 > Android开发

Android开发常用工具方法

2016-04-05 17:45 555 查看

MD5处理

/**
* 对String 进行md5加密
*
* @param input
* @return 32位字符串
*/
public static String md5(String input) {
String result = input;
if (input != null && !"".equals(input)) {
MessageDigest md; // or "SHA-1"
try {
md = MessageDigest.getInstance("MD5");
md.update(input.getBytes());
BigInteger hash = new BigInteger(1, md.digest());
result = hash.toString(16);
while (result.length() < 32) {
result = "0" + result;
}
} catch (NoSuchAlgorithmException e) {
e.printStackTrace(); // To change body of catch statement use
// File | Settings | File Templates.
}

}
return result;
}


Base64处理:

public static String base64Encode(String input ){
String  result = new String(Base64.encode(input.getBytes(),Base64.DEFAULT));
return  result;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: