新浪微博登录密码加密函数

// 新浪微博登录密码加密函数 // password 密码明文 // servertime 提交的参数之一 // nonce 提交的参数之一 // encode_password 输出的加密后的16进制字符串,40个字符 // 返回 encode_password 的长度, 失败则返回0 PASSENCODE_API int SinaSha1Encode(char *password, char *servertime, char *nonce, char *encode_password) { if (encode_password) { encode_password[0]=NULL; //定义要sha1的字符串 char pTemp[400]={0}; //定义返回的sha1值 char szHash[41] ={0}; strcpy(pTemp,password); SHA1((unsigned char*)pTemp, szHash, 41); strcpy(pTemp,szHash); SHA1((unsigned char*)pTemp, szHash, 41); strcpy(pTemp,szHash); if (servertime) strcat(pTemp,servertime); if (nonce) strcat(pTemp,nonce); SHA1((unsigned char*)pTemp, szHash, 41); strcpy(encode_password,szHash); return strlen(encode_password); } return 0; } //登陆伪代码 //*********************************************** ByteBuffer bytes; string url; string username="[email protected]"; string password="mima"; string encode_password; url="http://login.sina.com.cn/sso/prelogin.php?&entry=sso&username="; url+=username; url+="&callback=parent.sinaSSOController.loginCallBack"; BOOL bHtmlText; BOOL bUTF8; string retcode; string servertime; string nonce; if (GetUrlData(url.c_str(),bytes,NULL,0,bHtmlText,bUTF8) && bytes.getLength() && bHtmlText) { string str=bytes.c_str(); string::size_type pos(0),posend(0); if( (pos=str.find("{",posend))!=string::npos && (posend=str.find("}", ++pos))!=string::npos ) { string result=str.substr(pos,posend-pos); replace_all(result,"/"",""); TRACE(result.c_str()); vector vars; Split(result,vars,","); if (vars.size()) { for (int i=0;i keys; Split(vars[i],keys,":"); if (keys.size()==2) { if (keys[0]=="retcode") { retcode=keys[1]; }else if (keys[0]=="servertime") { servertime=keys[1]; }else if (keys[0]=="nonce") { nonce=keys[1]; }else{ TRACE("key:%s val:%s",keys[0].c_str(),keys[1].c_str()); } } } } } } if (atoi(retcode.c_str())==0) { EncodePasword(password,servertime,nonce,encode_password); TRACE("servertime:%s",servertime.c_str()); TRACE("nonce:%s",nonce.c_str()); TRACE("encode_password:%s",encode_password.c_str()); url="http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.3.12)"; string post; /* service=miniblog&client=ssologin.js%28v1.3.12%29&entry=miniblog&encoding=utf- 8&gateway=1&savestate=7&from=&useticket=1&username=diyiwl@sina.com&servertime=1306503150&nonce=IN4GY9&pwencode=wsse&password=74dd6f5f82e027412b6da345909f0df450b5f410&url=http% 3A%2F%2Fweibo.com%2Fajaxlogin.php%3Fframelogin%3D1%26callback%3Dparent.sinaSSOController.feedBackUrlCallBack&returntype=META&ssosimplelogin=1 */ post="service=miniblog&client=ssologin.js%28v1.3.12%29&entry=miniblog&encoding=GB2312&gateway=1&savestate=7&from=&useticket=1&username="; post+=username; post+="&servertime="; post+=servertime; post+="&nonce="; post+=nonce; post+="&pwencode=wsse&password="; post+=encode_password; post+="&url=http%3A%2F%2Fweibo.com%2Fajaxlogin.php%3Fframelogin%3D1%26callback%3Dparent.sinaSSOController.feedBackUrlCallBack&returntype=META&ssosimplelogin=1"; TRACE(url.c_str()); TRACE(post.c_str()); if (GetUrlData(url.c_str(),bytes,post.c_str(),post.length(),bHtmlText,bUTF8) && bytes.getLength() && bHtmlText) { TRACE(bytes.c_str()); } } //**********************************************

你可能感兴趣的:(杂项)