百度登录过程比较复杂,使用了rsa加密
实现过程有如下步骤
obj.log=Logger.getLogger(TestShareDown.class);
obj.log.info("1、开始第一次请求,用于获取cookie\r\n");
obj.reqJust();
obj.log.info("2、开始获取token\r\n");
obj.reqToken();
obj.log.info("3、开始获取验证码信息\r\n");
obj.reqImgCodeInfo();
obj.log.info("4、开始下载图片和获取验证码输入\r\n");
obj.getInputImgCode();
obj.log.info("5、开始正确性\r\n");
obj.reqValidImgCode();
obj.log.info("6、开始获取rsa\r\n");
obj.reqRsaKey();
obj.log.info("7、开始加密登录密码\r\n");
obj.ecnPassword();
obj.log.info("8、开始登录\r\n");
obj.reqLogin();
obj.log.info("9、开始获取bdstoken\r\n");
obj.reqBdstoken();
其实核心的过程就是根据百度返回的rsa加密密码
public void ecnPassword() throws Exception {
byte[] decodeBase64 = Base64.decodeBase64(pubkey);
X509EncodedKeySpec x509 = new X509EncodedKeySpec(decodeBase64);
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PublicKey publicKey = keyFactory.generatePublic(x509);
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
encPwd = Base64.encodeBase64String(cipher.doFinal("123qwe"
.getBytes()));
log.info("加密后密码:"+encPwd+"\r\n");
}