ITeye博客

加密123

sdustyongz · 2013-05-08 22:35 · java 学习 · 编程语言 · Markdown

/**

  • 加密传输时的密码
  • @author weirhp@gmail.com
  • http://weibo.com/weirhp */ public class EncodeQQPass {
public static void main(String args) {
    System.out.println(encodePass("yourpass", "!CEY",
            "\\x00\\x00\\x00\\x00\\x35\\x33\\x5f\\x58"));
}

public static String encodePass(String password, String vcode, String uin) {
    String us = uin.split("\\\\x");
    byte uinByte = new byte;
    if (us.length == 9) {
        for (int i = 1; i < us.length; i++) {
            uinByte = getByte(Integer.parseInt(us*, 16));
        }
    }
    return md5(md5(getByte(hexchar2bin(md5(password)), uinByte))
            + vcode.toUpperCase());
}

public static String md5(byte source) {
    String s = null;
    char hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
            'a', 'b', 'c', 'd', 'e', 'f' };
    try {
        java.security.MessageDigest md = java.security.MessageDigest
                .getInstance("MD5");
        md.update(source);
        byte tmp = md.digest();
        char str = new char;
        int k = 0;
        for (int i = 0; i < 16; i++) {
            byte byte0 = tmp*;
            str = hexDigits;
            str = hexDigits;
        }
        s = new String(str);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return s.toUpperCase();
}

public static String md5(String str) {
    return md5(str.getBytes()).toUpperCase();
}

public static byte hexchar2bin(String str) {
    byte bytes = new byte;
    int j = 0;
    for (int i = 0; i < str.length(); i = i + 2) {
        int iv = Integer.parseInt(str.substring(i, i + 2), 16);
        bytes = getByte(iv);
    }
    return bytes;
}

public static byte getByte(int intValue) {
    int byteValue = 0;
    int temp = intValue % 256;
    if (intValue < 0) {
        byteValue = temp < -128 ? 256 + temp : temp;
    } else {
        byteValue = temp > 127 ? temp - 256 : temp;
    }
    return (byte) byteValue;
}

public static byte getByte(byte b1, byte b2) {
    byte bs = new byte;
    int i = 0;
    for (i = 0; i < b1.length; i++) {
        bs* = b1*;
    }
    for (int j = 0; j < b2.length; j++) {
        bs = b2;
    }
    return bs;
}

}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。