问题描述
privatestaticStringmd5Digest(StringspId,StringspPassword,StringtimeStamp){try{MessageDigestmd=MessageDigest.getInstance("MD5");md.update(spId.getBytes());md.update(spPassword.getBytes());md.update(timeStamp.getBytes());byte[]b=md.digest();Stringresult="";Stringtemp="";//取摘要锟斤拷前16锟街斤拷for(inti=0;i<16;i++){temp=Integer.toHexString(b[i]&0xFF);if(temp.length()==1)temp="0"+temp;result+=temp;}//MD5锟斤拷锟斤拷转锟斤拷为锟斤拷写result=result.toUpperCase();returnresult;}catch(NoSuchAlgorithmExceptione){e.printStackTrace();returnnull;}catch(Exceptione){e.printStackTrace();returnnull;}}万分感谢
解决方案
解决方案二:
publicstringEncryptPassword(stringPasswordString,stringPasswordFormat){stringencryptPassword=null;if(PasswordFormat="SHA1"){encryptPassword=FormsAuthortication.HashPasswordForStoringInConfigFile(PasswordString,"SHA1");}elseif(PasswordFormat="MD5"){encryptPassword=FormsAuthortication.HashPasswordForStoringInConfigFile(PasswordString,"MD5");}returnencryptPassword;}
解决方案三:
学习
解决方案四:
MD5md5=newMD5CryptoServiceProvider();DESdes=newDESCryptoServiceProvider();byte[]res=md5.ComputeHash(Encoding.Default.GetBytes(input),0,input.Length);StringreturnThis="";for(inti=0;i<res.Length;i++){returnThis+=System.Uri.HexEscape((char)res[i]);}returnThis=returnThis.Replace("%","");returnThis=returnThis.ToLower();returnreturnThis;