0


md5加密 前后端不一致问题

md5加密 前后端不一致问题

java实现:

String key =Md5EncordUtil.getCode(str);//方法调用/**
 * 获取MD5加密后32位
 * @author lx
 *
 */publicclassMd5EncordUtil{
   publicstaticStringgetCode(String str){
   try{
   MessageDigest obj =MessageDigest.getInstance("MD5");
            obj.update(str.getBytes("UTF-8"));byte[] digest = obj.digest();finalStringBuffer buffer =newStringBuffer();for(int i =0; i < digest.length;++i){
   finalbyte b = digest[i];finalint value =(b &0x7F)+(b <0?128:0);
                buffer.append(value <16?"0":"");
                buffer.append(Integer.toHexString(value));}return buffer.toString();}catch(NoSuchAlgorithmException e){
   
            e.printStackTrace();}catch(UnsupportedEncodingException e){
   
            e.printStackTrace();}returnnull;}}

前端js原生代码实现:

var key =md5(str,32);//方法调用//字符串md5加密functionmd5(string,bit){
   functionmd5_RotateLeft(lValue, iShiftBits){
   return(lValue << iShiftBits)|(lValue >>>(32- iShiftBits));}functionmd5_AddUnsigned(lX, lY){
   var lX4, lY4, lX8, lY8, lResult;
        lX8 =(lX &0x80000000);
        lY8 =(lY &0x80000000);
        lX4 =(lX &0x40000000);
        lY4 =(lY &0x40000000);
        lResult =(lX &0x3FFFFFFF)+(lY &0x3FFFFFFF);if(lX4 & lY4){
   return(lResult ^0x80000000^ lX8 ^ lY8);}if(lX4 | lY4){
   if(lResult &0x40000000){
   return(lResult ^0xC0000000^ lX8 ^ lY8);}else{
   return(lResult ^0x40000000^ lX8 ^ lY8);}}else{
   return(lResult ^ lX8 ^ lY8);}}functionmd5_F(x, y, z){
   return(x & y)|((~x)& z);}functionmd5_G(x, y, z){
   return(x & z)|(y &(~z));}functionmd5_H(x, y, z){
   return(x ^ y ^ z);}functionmd5_I(x, y, z){
   return(y ^(x |(~z)));}functionmd5_FF(a, b, c, d, x, s, ac){
   
        a =md5_AddUnsigned(a,md5_AddUnsigned(md5_AddUnsigned(md5_F(b, c, d), x), ac));returnmd5_AddUnsigned(md5_RotateLeft(a, s), b);};functionmd5_GG(a, b, c, d, x, s, ac){
   
        a =md5_AddUnsigned(a,

本文转载自: https://blog.csdn.net/qq_44725412/article/details/130339426
版权归原作者 .添砖java 所有, 如有侵权,请联系我们删除。

“md5加密 前后端不一致问题”的评论:

还没有评论