JAVA下wordpress加密

来源:互联网 发布:手机4g网络测速在线 编辑:程序博客网 时间:2024/06/06 03:04

这个加密找了很久,都只有PHP版本的,同事给了我一个远古的C#版本的,写的太晦涩难懂,而且还有错的,不过最后好歹弄出来的。上代码

//wordpress 加密public String WordpressEncrypt(String str,String salt){MessageDigest md;try {md = MessageDigest.getInstance("MD5");byte[] hash = md.digest((salt + str).getBytes());byte[] palin = str.getBytes();for(int i = 0;i < 8192;i++){byte[] newplain = new byte[hash.length + palin.length];System.arraycopy(hash, 0, newplain, 0, hash.length);System.arraycopy(palin, 0, newplain, hash.length, palin.length);//MD5加密MessageDigest md5 = MessageDigest.getInstance("MD5");hash = md5.digest(newplain);}int[] x = new int[hash.length];for(int i = 0;i < hash.length;i++){x[i] = hash[i] & 0xff;}//System.out.println(re);//return re;return "$P$B" + salt + encode64(x, 16);//return String.valueOf(hash.length);} catch (NoSuchAlgorithmException e) {// TODO Auto-generated catch blocke.printStackTrace();return "fail";}}private String encode64(int[] input, int number){        String hash = "";        int output = 0;        int[] input_2 = new int[number];        for (int i = 0; i < number; i++)        {            input_2[i] = input[i];            //text_2.Text += "'" + input_2[i] + "'" ;         }         String itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";         int output_2 = 0;         int len_2 = 0;         int value_2 = 0;         for (int i = 0; i <number;i++ )         {             int value = input_2[i];             output = input_2[i];             hash += itoa64.substring((value % 64 + 64)%64, (value % 64 + 64)%64 + 1);             if (i + 1 <= number)             {                 if (i + 1 < number)                 {                     value = input_2[++i];                     output_2 = (value << 8);//左移8位                     output = output + output_2;                 }                                 value_2 = output;                 int len = Integer.toBinaryString(output).length();                 if (len - 6 > 0)                 {                     output = (output >> 6);//右移6位                 }                 else                 {                     output = 0;                 }                 value = output;                 hash += itoa64.substring((value % 64 + 64)%64, (value % 64 + 64)%64 + 1);             }             else             {                 break;             }             if (i + 1 < number)             {                 value = input_2[++i];                 output_2 = (value << 16);//左移16位                 output = value_2 + output_2;                 value_2 = output;                 len_2 = Integer.toBinaryString(output).length();                 output_2 = output;                 output = (output >> 12);//右移12位                 value = output;//                 hash += itoa64.substring((value % 64 + 64)%64, (value % 64 + 64)%64 + 1);             }             else             {                 break;             }             if (i+1< number)             {                 len_2 = Integer.toBinaryString(output_2).length();                 output = (output_2 >> 18);//右移18位                 value = output;//                 hash += itoa64.substring((value % 64 + 64)%64, (value % 64 + 64)%64 + 1);             }         }        return hash; //*/    }



0 0