java qq 密码加密_腾讯登录加密方式的java实现

本文转载自 :http://hi.baidu.com/royripple/item/8bbf740fef8783cc75cd3ce0

腾讯登录加密方式的java实现,使用这个就不用再用jsEngine来做MD5加密

2012-6-13号更新可用。

另外,登录链接已改成如下:

get=new HttpGet("http://ptlogin2.qq.com/login?ptlang=2052&u="+Config.USERNAME+"&p="+pass+"&verifycode="+checkNum[1]+"&low_login_enable=1&low_login_hour=720&aid=46000101&u1=http%3A%2F%2Ft.qq.com&ptredirect=1&h=1&from_ui=1&dumy=&fp=loginerroralert&action=1-2-11125&g=1&t=1&dummy=");

成功返回:

ptuiCB('0','0','http://t.qq.com','1','登录成功!', 'roy');

========================================================

加密代码:

import java.io.ByteArrayOutputStream;

import java.io.UnsupportedEncodingException;

import java.security.MessageDigest;

public class MD5Security {

public static final String HEXSTRING = "0123456789ABCDEF";

public static String md5(String originalText) throws Exception {

byte buf[] = originalText.getBytes("ISO-8859-1");

StringBuffer hexString = new StringBuffer();

String result = "";

String digit = "";

try {

MessageDigest algorithm = MessageDigest.getInstance("MD5");

algorithm.reset();

algorithm.update(buf);

byte[] digest = algorithm.digest();

for (int i = 0; i 

digit = Integer.toHexString(0xFF & digest[i]);

if (digit.length() == 1) {

digit = "0" + digit;

}

hexString.append(digit);

}

result = hexString.toString();

} catch (Exception ex) {

result = "";

}

return result.toUpperCase();

}

public static String hexchar2bin(String md5str) throws UnsupportedEncodingException

{

ByteArrayOutputStream baos = new ByteArrayOutputStream(md5str.length() / 2);

for (int i = 0; i 

{

baos.write((HEXSTRING.indexOf(md5str.charAt(i)) <

HEXSTRING.indexOf(md5str.charAt(i + 1))));

}

return new String(baos.toByteArray(), "ISO-8859-1");

}

/**

*

* @param qq http://check.ptlogin2.qq.com/check?uin={0}&appid=15000101&r={1} 返回的第三个值

* @param password QQ密码

* @param verifycode 验证码

* @return 加密后的密码

* @throws UnsupportedEncodingException

* @throws Exception

*/

public static String GetPassword(String qq,String password, String verifycode) throws Exception{

String P = hexchar2bin(md5(password));

String U = md5(P + hexchar2bin(qq.replace("\\x", "").toUpperCase()));

String V = md5(U + verifycode.toUpperCase());

return V;

}

public static void main(String[] args) throws Exception {

System.out.println(GetPassword("\\x00\\x00\\x00\\x00\\x90\\xbe\\x76\\xce","royripple1989082","!1VM"));

//System.out.println(md5("\\x00\\x00\\x00\\x00\\x90\\xbe\\x76\\xce"));

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值