Android md5加密与php md5加密一致详解
Androidmd5加密与phpmd5加密一致详解
在Android开发过程中加密密码常常采用md5加密方式,然而如果服务器端采用PHP开发(php采用md5加密很简单,直接md5($str)),很可能与Java的md5加密不一致。以下方法是md5加密与php一致的源码:
importjava.math.BigInteger;
importjava.security.MessageDigest;
importjava.security.NoSuchAlgorithmException;
publicclassMD5{
//密码加密与php加密一致
publicstaticStringmd5(Stringinput)throwsNoSuchAlgorithmException{
Stringresult=input;
if(input!=null){
MessageDigestmd=MessageDigest.getInstance("MD5");//or"SHA-1"
md.update(input.getBytes());
BigIntegerhash=newBigInteger(1,md.digest());
result=hash.toString(16);
while(result.length()<32){//31位string
result="0"+result;
}
}
returnresult;
}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短