加密123

/**
* 加密传输时的密码
* @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[us.length - 1];
if (us.length == 9) {
for (int i = 1; i < us.length; i++) {
uinByte[i - 1] = getByte(Integer.parseInt(us[i], 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[16 * 2];
int k = 0;
for (int i = 0; i < 16; i++) {
byte byte0 = tmp[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
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[str.length() / 2];
int j = 0;
for (int i = 0; i < str.length(); i = i + 2) {
int iv = Integer.parseInt(str.substring(i, i + 2), 16);
bytes[j++] = 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[b1.length + b2.length];
int i = 0;
for (i = 0; i < b1.length; i++) {
bs[i] = b1[i];
}
for (int j = 0; j < b2.length; j++) {
bs[i + j] = b2[j];
}
return bs;
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值