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 婆婆高寿祝福语大全简短