【旧代码整理】Nodejs的另类用法
来源:互联网 发布:vm虚拟机网络连接 编辑:程序博客网 时间:2024/05/19 17:58
Nodejs 的中文维基百科介绍:https://zh.wikipedia.org/wiki/Node.js
Nodejs 可以 在linux命令行执行js代码。
比如:
var a = 1;var b = 2;var c = a + b;console.log(c+"\r");
以上代码保存为 test.js
然后执行命令:
joyatonce@bananabook:~/# nodejs test.js3
再看下面,用nodejs执行新浪微博登录加密密码的js:(这堆代码是别人整理的,我只是稍稍改了下)
var window = {location : {hash : '',host : 'weibo.com',hostname : 'weibo.com',href : 'http://weibo.com/',pathname : '/',port : '',protocol : 'http:',search : ''},navigator : {appCodeName : 'Mozilla',appName : 'Netscape',appVersion : '5.0 (Macintosh)',buildID : '20120713134347',cookieEnabled : true,doNotTrack : 'unspecified',language : 'en-US'}};var location = window.location;var navigator = window.navigator;/** * ssologin.js */function SSOController() {var me = this; // use in private function var updateCookieTimer = null;var updateCookieTimeHardLimit = 1800; // 在该时间内不允许更新cookie,默认30分钟var cookieExpireTimeLength = 3600 * 24; // cookie过期时间为24小时var crossDomainForward = null ; // 广播操作完成后执行的动作var crossDomainTimer = null;var crossDomainTime = 3; // 允许广播操作的最大时间var autoLoginCallBack2 = null;var ssoCrosssDomainUrl = 'http://login.sina.com.cn/sso/crossdomain.php';var ssoLoginUrl = 'http://login.sina.com.cn/sso/login.php';var ssoLogoutUrl = 'http://login.sina.com.cn/sso/logout.php';var ssoUpdateCookieUrl = 'http://login.sina.com.cn/sso/updatetgt.php';var ssoPreLoginUrl = 'http://login.sina.com.cn/sso/prelogin.php';var ssoCheckAltLoginNameUrl = 'http://login.sina.com.cn/bindmail/checkmailuser.php';var pincodeUrl = 'http://login.sina.com.cn/cgi/pin.php';var vfValidUrl = 'http://weibo.com/sguide/vdun.php';var crossDomainUrlList = null;var loginMethod = ""; // post or get ,方便登录后的处理var checkAltLoginNameCallbackData = {};var ssoCheckAltLoginNameScriptId = 'check_alt_login';var ssoServerTimeTimer = null;var ssoLoginTimer = null;var loginByConfig = null; // 为再次登录使用var loginMethodCheck = null; // 为再次登录使用var https = 1;//write onlyvar rsa = 2;//write onlyvar wsse = 4;//write only var pcid = "";//pincode idvar tmpData = {};var preloginTimeStart = 0;var preloginTime = 0;this.https = 1; //read onlythis.rsa = 2;//read onlythis.wsse = 4;//read onlythis.name = 'sinaSSOController';this.loginFormId = 'ssoLoginForm';this.scriptId = 'ssoLoginScript';this.ssoCrossDomainScriptId = 'ssoCrossDomainScriptId';this.loginFrameName = 'ssoLoginFrame';this.appLoginURL = {'51uc.com':'http://passport.51uc.com/sso/login.php','weibo.com':'http://weibo.com/sso/login.php'};this.appDomainService = {'51uc.com':'51uc','weibo.com':'miniblog'};this.loginExtraQuery = {};//需要配置的内容this.setDomain = false; // 为向下兼容提供的开启新特性的参数this.feedBackUrl = '';this.service = 'sso';this.domain = 'sina.com.cn'; // sina.com.cn 域的产品不许需要该设置this.from = ''; // 请求的具体来源,比entry更具体this.pageCharset = 'GB2312'; // 页面的编码,主要是用于认证,默认为GB2312this.useTicket = false; // 登录成功或失败后是否返回ticket,默认为falsethis.isCheckLoginState = false; // 初始化时是否检查登录状态, 检查将调feedBackUrl ,所以默认不检查this.isUpdateCookieOnLoad = true; // 是否在加载该js文件后自动更新一次cookie,默认为自动更新,如果自定义了回调函数,请不要自动更新cookiethis.useIframe = true; // 默认使用iframe 做post方式的登录,如果不能提供feedBackUrl,将不能使用该方式,改配置选项不出现在文档中this.noActiveTime = 7200; // 不活跃时长,默认2小时this.autoUpdateCookieTime = 1800; // 页面不动时自动更新cookie的间隔时间,默认30分钟,少于5s不做更新this.loginType = rsa; // 默认rsa方式this.timeoutEnable = false;this.crossDomain = true; // default truethis.scriptLoginHttps = false; // 当使用post方式登录失败后,转换为script标签方式的登录是否强制使用https的方式登录,默认使用wsse方式登录this.allowAutoFoundServerTime = false; //是否自动发现服务器端时间,默认不自动发现,至少非登录页面也在使用该js,这些页面就不关心服务器时间了this.allowAutoFoundServerTimeError = true; //是否自动发现服务器端时间错误this.calcServerTimeInterval = 2000; //2sthis.servertime = null;this.nonce = null;this.rsaPubkey = null;this.rsakv = null;this.loginExtraFlag = {};this.cdult = false;this.crossDomainTime = 5;this.failRedirect = false; //当遇到需要跳转的页面时,当前页面是否支持跳转。this.getVersion = function() {return "ssologin.js(v1.4.2) 2012-8-21";};this.getEntry = function() {return me["entry"];};this.getClientType = function() {return me.getVersion().split(' ')[0];};this.init = function() {me.setLoginType(me.loginType); // 检查是否需要使用httpsvar ssoConfig = window["sinaSSOConfig"];if(typeof ssoConfig != "object" ) {ssoConfig = {};}//maping config setvar name;for (name in ssoConfig) {me[name] = ssoConfig[name];}if (!me["entry"]) me["entry"] = me["service"];if(me.isUpdateCookieOnLoad) {setTimeout(me.name+".updateCookie()",10000);}//访问feedBackUrl检查登录状态,feedBackUrl可能会转向ssoLoginUrl取状态if(me.isCheckLoginState) {addEventListener(window,"load",function(){me.checkLoginState();});}//试图从页面中发现ssoServerTime,作为登录的初始时间if(me.allowAutoFoundServerTime && ssoLoginServerTime) me.setServerTime(ssoLoginServerTime);me.customInit();};this.customInit = function() {};this.customUpdateCookieCallBack = function(result) {// 不需要关心该方法};this.customLogoutCallBack = function(result) {me.customLoginCallBack({"result":false});};/** * 此函数为用户可覆盖的回调函数,loginStatus参数为用户的登录状态 * 为false则未登录 * 否则会显示用户的登录信息数组 */this.customLoginCallBack = function(loginStatus) {// 该方法由产品自己来定义};this.login = function(username, password, savestate) {if (!ssoLoginTimer) {ssoLoginTimer = new prototypeTimer(me.timeoutEnable);} else {ssoLoginTimer.clear();}ssoLoginTimer.start(5000, function(){ssoLoginTimer.clear(); // 这里如果不清除时钟,则迟到的登录依然会显示登录结果me.customLoginCallBack({"result":false,"reason":unescape("%u767B%u5F55%u8D85%u65F6%uFF0C%u8BF7%u91CD%u8BD5")});});savestate = savestate == undefined ?0:savestate;tmpData['savestate'] = savestate;loginByConfig = function() {if(me.useIframe && (me.setDomain || me.feedBackUrl) ) {if (me.setDomain) {document.domain = me.domain;if (!me.feedBackUrl && me.domain != "sina.com.cn") me.feedBackUrl = makeURL(me.appLoginURL[me.domain], {"domain":1});}loginMethod = "post";var result = loginByIframe(username,password,savestate);if (!result) {loginMethod = "get";if (me.scriptLoginHttps) {me.setLoginType(me.loginType | https);} else {me.setLoginType(me.loginType | rsa);}loginByScript(username,password,savestate);}} else {loginMethod = "get";loginByScript(username,password,savestate);}me.nonce = null;};loginMethodCheck = function() {if ((me.loginType & wsse) || (me.loginType & rsa)) {if (me.servertime) {if (!me.nonce) me.nonce = makeNonce(6);loginByConfig();return true;}// get servertimeme.getServerTime(username, loginByConfig);} else {loginByConfig();}};loginMethodCheck();return true;};this.getServerTime = function(username, callback) {if (me.servertime) {if(typeof callback == "function") callback({"retcode":0,"servertime":me.servertime});return true;}var url = location.protocol == "https:"?ssoPreLoginUrl.replace(/^http:/,"https:"):ssoPreLoginUrl;//对username进行base64编码username = sinaSSOEncoder.base64.encode(urlencode(username));url = makeURL(url,{"entry":me.entry,"callback":me.name+".preloginCallBack","su":username,"rsakt":"mod"});me.preloginCallBack = function(result) {if(result && result.retcode == 0) {me.setServerTime(result.servertime);me.nonce = result.nonce;me.rsaPubkey = result.pubkey;me.rsakv = result.rsakv; pcid = result.pcid;preloginTime = (new Date()).getTime() - preloginTimeStart;}if(typeof callback == "function") callback(result);};preloginTimeStart = (new Date()).getTime();excuteScript(me.scriptId, url);};this.logout = function() {try {var request = {'entry':me.getEntry(),'callback':me.name + '.ssoLogoutCallBack'};var url = location.protocol == "https:"?ssoLogoutUrl.replace(/^http:/,"https:"):ssoLogoutUrl;url = makeURL(url, request);excuteScript(me.scriptId, url);} catch (e) {}return true;};this.ssoLogoutCallBack = function (result) {if (result.arrURL) {me.setCrossDomainUrlList(result);}me.crossDomainAction('logout',function(){me.customLogoutCallBack({'result':true});});};this.updateCookie= function() {try {if(me.autoUpdateCookieTime > 5) {if(updateCookieTimer != null) {clearTimeout(updateCookieTimer);}updateCookieTimer = setTimeout(me.name+".updateCookie()",me.autoUpdateCookieTime * 1000); // convert to millisecond}var cookieExpireTime = me.getCookieExpireTime();var now = (new Date()).getTime() / 1000; // convert to secondvar result = {};if (cookieExpireTime == null) { // cookie 不存在result = {"retcode":6102}; // not login} else if( cookieExpireTime < now ) { // cookie 已经过期result = {"retcode":6203}; // cookie expired} else if( cookieExpireTime - cookieExpireTimeLength + updateCookieTimeHardLimit > now) { // 在硬限制的时间内不允许更新cookieresult = {"retcode":6110};} else if(cookieExpireTime - now > me.noActiveTime) {// 离过期还早着呢result = {"retcode":6111};}if(result.retcode !== undefined) { me.customUpdateCookieCallBack(result);return false;}var url = location.protocol == "https:"?ssoUpdateCookieUrl.replace(/^http:/, "https:"):ssoUpdateCookieUrl;url = makeURL(url, {"entry":me.getEntry(),"callback":me.name + ".updateCookieCallBack"});excuteScript(me.scriptId, url );} catch (e) {}return true;};// 设置需要广播的地址列表this.setCrossDomainUrlList = function(urlList) {crossDomainUrlList = urlList;};// 检查用户名的备选登录方式// 并且对接口返回值做了一些封装。this.checkAltLoginNameCallback = function (data){var ret = {'retcode' : 0, 'detail' : '', 'data' : ''};if(data.ret == "y") {ret['retcode'] = 1;ret['detail'] = '\u4e3a\u4e86\u60a8\u7684\u8d26\u53f7\u5b89\u5168\uff0c\u8bf7<a href="http://login.sina.com.cn/bindmail/signin.php?username=' +checkAltLoginNameCallbackData['username']+ '">\u7ed1\u5b9a\u90ae\u7bb1</a>';ret['data'] = checkAltLoginNameCallbackData['username'];} else if(data.ret == "n" && data.mail) {if (data.errcode == 'not_verify') {ret['retcode'] = 2;ret['detail'] = '\u60a8\u7684\u90ae\u7bb1: '+data.mail+' \u672a\u9a8c\u8bc1\uff0c\u70b9\u6b64<a href="http://login.sina.com.cn/bindmail/bindmail1.php?entry=sso&user='+data.mail+'">\u91cd\u53d1\u9a8c\u8bc1\u90ae\u4ef6</a>';ret['data'] = data.mail;} else {ret['retcode'] = 3;ret['detail'] = '\u7528\u60a8\u7684\u90ae\u7bb1'+data.mail+'\u4e5f\u53ef\u4ee5\u767b\u5f55';ret['data'] = data.mail;}}else{// do nothing// and hide the wrong code returned by api. }checkAltLoginNameCallbackData['callback'](ret);};this.checkAltLoginName = function(username, callback){if( username == ""){return true;}var r = /^[0-9]{1,9}$/;if (r.exec(username)){return true;}checkAltLoginNameCallbackData = {'username' : username, 'callback' : callback};var url = (me.loginType & https)?ssoCheckAltLoginNameUrl.replace(/^http:/,"https:"):ssoCheckAltLoginNameUrl;url = makeURL(url, {'name': username, 'type':'json', 'callback':'sinaSSOController.checkAltLoginNameCallback'});excuteScript(ssoCheckAltLoginNameScriptId, url);};this.callFeedBackUrl = function(loginStatus) {try {var request = {'callback':me.name + ".feedBackUrlCallBack"};if(loginStatus['ticket']) {request['ticket'] = loginStatus['ticket'];}if(loginStatus['retcode'] !== undefined) {request['retcode'] = loginStatus['retcode'];}var url = makeURL(me.feedBackUrl, request);excuteScript(me.scriptId,url);} catch (e) {}return true;};// 登录回调函数,script标签登录或setDomain方式登录时使用该回调函数this.loginCallBack = function(result) {try {if(me.timeoutEnable && !ssoLoginTimer.isset()) return;ssoLoginTimer.clear();me.loginExtraFlag = {}; //清空与本次登录相关的标识var loginStatus = {};var st = result["ticket"];var uid = result["uid"];if(uid) {loginStatus['result'] = true;loginStatus['retcode'] = 0;loginStatus['userinfo'] = {"uniqueid":result["uid"]};if(st) loginStatus['ticket'] = st;if (me.feedBackUrl) {if (me.crossDomain) {me.crossDomainAction("login",function(){me.callFeedBackUrl(loginStatus);});} else {me.callFeedBackUrl(loginStatus);}} else {if (me.crossDomain) {if (result["crossDomainUrlList"]) {me.setCrossDomainUrlList({"retcode":0,"arrURL":result["crossDomainUrlList"]});}me.crossDomainAction("login",function(){if (st && me.appLoginURL[me.domain]) {me.appLogin(st, me.domain, me.name + ".customLoginCallBack");} else {loginStatus["userinfo"] = objMerge(loginStatus["userinfo"], me.getSinaCookie());me.customLoginCallBack(loginStatus);}});} else {me.customLoginCallBack(loginStatus);}}} else {// 服务器端时间设置不正确的容错if (loginMethodCheck && result['retcode'] == "2092" && me.allowAutoFoundServerTimeError) {me.setServerTime(0); // 重置服务器时间的值,便于重新获取me.loginExtraFlag = objMerge(me.loginExtraFlag,{"wsseretry":"servertime_error"}); // 添加重试标识,便于了解情况loginMethodCheck(); // 重新登录一次,这次没有了登录超时的控制了,实现起来麻烦而且没有必要loginMethodCheck = null; //避免死循环return false;}loginStatus['result'] = false;loginStatus['errno'] = result['retcode'];if (loginStatus['errno'] == '4069') { //尝试跳转进行额外认证var reason = result['reason'].split('|');loginStatus['reason'] = reason[0];if (reason.length == 2) loginStatus['rurl'] = reason[1];if (loginStatus['rurl']) {try {top.location.href = loginStatus['rurl'];return;} catch (e) {}}} else {loginStatus['reason'] = result['reason'];}me.customLoginCallBack(loginStatus);}} catch (e) {}return true;};this.updateCookieCallBack = function (result) {if(result['retcode'] == 0) {me.crossDomainAction("update",function(){me.customUpdateCookieCallBack(result);});} else { // 忽略更新失败的情况,因为更新失败后的操作不是必须的me.customUpdateCookieCallBack(result);}};this.feedBackUrlCallBack = function (result) {// 对于给了feedBackUrl但是又强制get方式登录的时候,计时器在loginCallBack回调时已经清除了if(loginMethod == "post" && me.timeoutEnable && !ssoLoginTimer.isset()) return;ssoLoginTimer.clear();if (result.errno == "2092") {me.setServerTime(0); // 重置服务器时间的值,便于重新获取}if (result.errno == '4069') { // 需要跳转进行额外认证var reason = result.reason.split('|');result.reason = reason[0];if (reason.length == 2) {result.rurl = reason[1];try {top.location.href = result.rurl;return;} catch (e) {}}}me.customLoginCallBack(result);removeNode(me.loginFrameName);// 删除用完的iframe,但是一定不要在回调前删除,Firefox可能有问题的};this.doCrossDomainCallBack = function (result) {me.crossDomainCounter++;if(result)removeNode(result.scriptId);if(me.crossDomainCounter == me.crossDomainCount) {clearTimeout(crossDomainTimer);me.crossDomainResult();}};this.crossDomainCallBack = function(result) {// 如果存在获取广播地址列表的请求的script标签,则这里已经用过,删除之removeNode(me.ssoCrossDomainScriptId);if( !result || result.retcode != 0) {return false;}var arrURL = result.arrURL;var url, scriptId;var request = {'callback':me.name + '.doCrossDomainCallBack'};me.crossDomainCount = arrURL.length;me.crossDomainCounter = 0;if(arrURL.length == 0) { // 最初不需要通知任何域clearTimeout(crossDomainTimer);me.crossDomainResult();return true;}for(var i = 0; i < arrURL.length; i++) {url = arrURL[i];scriptId = 'ssoscript'+i;request.scriptId = scriptId;url = makeURL(url, request);if(isSafari()){//safari 需要用这个方法// http://wiki.intra.sina.com.cn/pages/viewpage.action?pageId=6297546excuteIframe(scriptId, url);}else{excuteScript(scriptId, url);}}};this.crossDomainResult = function () {// 清空广播列表,避免下次误用crossDomainUrlList = null;if(typeof crossDomainForward == 'function') {crossDomainForward();}};// 广播登录事件this.crossDomainAction = function (action,callback) {crossDomainTimer = setTimeout(me.name + '.crossDomainResult()',crossDomainTime * 1000);if(typeof callback == 'function') {crossDomainForward = callback;} else {crossDomainForward = null;}if (crossDomainUrlList) { // 已经存在了需要广播的地址列表me.crossDomainCallBack(crossDomainUrlList);return false;}// 还没有需要广播的地址列表,自己通过crossdomain.php 来获取var domain = me.domain;if(action == "update") {action = "login";domain = "sina.com.cn";}var request = {'scriptId':me.ssoCrossDomainScriptId,'callback':me.name + '.crossDomainCallBack','action':action,'domain':domain};var url = makeURL(ssoCrosssDomainUrl, request);excuteScript(me.ssoCrossDomainScriptId, url);};this.checkLoginState = function(callback) {if (callback) {me.autoLogin(callback); // the arguments of callback is cookieinfo or null} else {me.autoLogin(function(cookieinfo){var loginStatus = {};if (cookieinfo !== null) {var userinfo = {'displayname':cookieinfo['nick'],'uniqueid':cookieinfo['uid'],'userid':cookieinfo['user']};loginStatus["result"] = true;loginStatus["userinfo"] = userinfo;} else {loginStatus["result"] = false;loginStatus["reason"] = "";}me.customLoginCallBack(loginStatus);});}};this.getCookieExpireTime = function (){return getCookieExpireTimeByDomain(me.domain);};this.getSinaCookie = function (strict) {var sup = urldecode(getCookie("SUP"));if (!sup && !urldecode(getCookie("ALF"))) return null;if (!sup) sup = urldecode(getCookie("SUR"));if (!sup) return null;var arrSup = parse_str(sup);if (strict && arrSup["et"] && (arrSup["et"] * 1000 < (new Date()).getTime())) {return null;}return arrSup;};this.get51UCCookie = function() {return me.getSinaCookie();};this.autoLogin = function (callback) {if (me.domain == 'sina.com.cn') {if (getCookie('SUP') === null && getCookie('ALF') !== null ) {sinaAutoLogin(callback);return true;}} else {if (getCookie('SUP') === null && (getCookie('SSOLoginState') !== null || getCookie('ALF') !== null) ) {sinaAutoLogin(callback);return true;}}callback(me.getSinaCookie());return true;};this.autoLoginCallBack2 = function (result) {try {autoLoginCallBack2(me.getSinaCookie());} catch(e) {}return true;};this.appLogin = function(ticket, domain, callback) {var savestate = tmpData['savestate']?parseInt((new Date()).getTime()/1000 + tmpData['savestate'] * 86400):0;var alf = getCookie('ALF')?getCookie('ALF'):0;var request = {'callback': callback,'ticket': ticket,'ssosavestate': savestate || alf};var appLoginURL = me.appLoginURL[domain];var url = makeURL(appLoginURL, request);excuteScript(me.scriptId, url, "gb2312");return true;};this.autoLoginCallBack3 = function (result) {if (result['retcode'] != 0) {me.autoLoginCallBack2(result);return false;}me.appLogin(result["ticket"], me.domain, me.name + ".autoLoginCallBack2");return true;};this.setLoginType = function(loginType) {// 检查当前页面是否https,如果是,则强制使用https登录,否则浏览器有提示var https = location.protocol == "https:"?me.https:0;if (https) me.crossDomain = false;me.loginType = loginType | https;return true;};this.setServerTime = function(servertime) {if (!ssoServerTimeTimer) {ssoServerTimeTimer = new prototypeTimer(true);}// 重置服务器时间if (servertime == 0) {ssoServerTimeTimer.clear();me.servertime = servertime;return true;}// 避免设置不靠谱的时间if (servertime < 1294935546) return false;var calcServerTime = function() {if (me.servertime) {me.servertime += me.calcServerTimeInterval / 1000;ssoServerTimeTimer.start(me.calcServerTimeInterval, calcServerTime);}};me.servertime = servertime;ssoServerTimeTimer.start(me.calcServerTimeInterval, calcServerTime);};this.getPinCodeUrl = function (size) {if(size == undefined) {size = 0;}if (pcid) { me.loginExtraQuery.pcid = pcid;}var url = location.protocol == "https:"?pincodeUrl.replace(/^http:/, "https:"):pincodeUrl;return url + '?r=' + Math.floor( Math.random()*100000000 ) + '&s=' + size + (pcid.length > 0 ? '&p=' + pcid : '');};this.showPinCode = function(id) {me.$(id).src = me.getPinCodeUrl();};this.isVfValid = function(){return me.getSinaCookie(true)['vf'] != 1;};this.getVfValidUrl = function() {return vfValidUrl;};this.enableFailRedirect = function() {me.failRedirect = true;};var makeNonce = function(len) {var x = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";var str = "";for (var i = 0; i < len; i++ ) {str += x.charAt(Math.ceil(Math.random()*1000000)%x.length);}return str;};var sinaAutoLogin = function (callback) {autoLoginCallBack2 = callback;var request = {'entry':me.getEntry(),'service':me.service,'encoding':'UTF-8','gateway':1,'returntype':'TEXT','from':me.from};if (me.domain == 'sina.com.cn') {request['callback'] = me.name + '.autoLoginCallBack2';request['useticket'] = 0;} else {request['callback'] = me.name + '.autoLoginCallBack3';request['useticket'] = 1;}var url = location.protocol == "https:"?ssoLoginUrl.replace(/^http:/,"https:"):ssoLoginUrl;url = makeURL(url, request);excuteScript(me.scriptId, url, "gb2312");return true;};var getCookieExpireTimeByDomain = function (domain) {var expireTime = null;var cookie = null;cookie = me.getSinaCookie();if (cookie) expireTime = cookie['et'];return expireTime;};var addEventListener = function(dom, eventName, fn){if (dom.addEventListener) {dom.addEventListener(eventName, fn, false);} else if (dom.attachEvent) {dom.attachEvent("on" + eventName, fn);} else {dom["on" + eventName] = fn;}};var prototypeTimer = function(enable){var mytimer = false;this.start = function(timeout, callback) {if(enable) mytimer = setTimeout(callback, timeout);};this.clear = function(name) {if(enable) {clearTimeout(mytimer);mytimer = false;}};this.isset = function() {return mytimer !== false;};};// 此函数用来执行一个scriptvar excuteScript = function (id, scriptSource, charset) {removeNode(id);var head = document.getElementsByTagName('head')[0];var newScript = document.createElement('script');newScript.charset = charset || 'gb2312';newScript.id = id;newScript.type = 'text/javascript';newScript.src = makeURL(scriptSource, {"client":me.getClientType(), "_": (new Date()).getTime()}); head.appendChild(newScript);};//此函数用于进行一次iframe请求var excuteIframe = function(id, url){removeNode(id);var bodyel = document.getElementsByTagName('body')[0];var new_iframe = document.createElement('iframe');new_iframe.style.display = 'none';new_iframe.src = makeURL(url, {"client":me.getClientType(), "_": (new Date()).getTime()});new_iframe.isReady = false;addEventListener(new_iframe, 'load', function(){if(new_iframe.isReady){return;}new_iframe.isReady = true;me.doCrossDomainCallBack({scriptId:id});});bodyel.appendChild(new_iframe);};var makeRequest = function(username, password, savestate) {var request = {"entry": me.getEntry(),"gateway": 1,"from": me.from,"savestate": savestate,"useticket": me.useTicket?1:0};if (me.failRedirect) {me.loginExtraQuery.frd = 1;}request = objMerge(request, me.loginExtraFlag);request = objMerge(request, me.loginExtraQuery);request["su"] = sinaSSOEncoder.base64.encode(urlencode(username)); // su是username的别名if (me.service) request["service"] = me.service;if((me.loginType & rsa) && me.servertime && sinaSSOEncoder && sinaSSOEncoder.RSAKey){request["servertime"] = me.servertime;request["nonce"] = me.nonce;request["pwencode"] = "rsa2";request["rsakv"] = me.rsakv;var RSAKey = new sinaSSOEncoder.RSAKey();RSAKey.setPublic(me.rsaPubkey, '10001');password = RSAKey.encrypt([me.servertime, me.nonce].join("\t") + "\n" + password);}else if ((me.loginType & wsse) && me.servertime && sinaSSOEncoder && sinaSSOEncoder.hex_sha1) {request["servertime"] = me.servertime;request["nonce"] = me.nonce;request["pwencode"] = "wsse";password = sinaSSOEncoder.hex_sha1("" + sinaSSOEncoder.hex_sha1(sinaSSOEncoder.hex_sha1(password)) + me.servertime + me.nonce); // 空字符串为了避免各项全部是数字时造成数字相加而不是字符串链接的情况}request["sp"] = password; // sp是password的别名return request;};// login by scriptvar loginByScript = function (username,password,savestate) {if (me.appLoginURL[me.domain]) {me.useTicket = 1;me.service = me.appDomainService[me.domain] || me.service; // UNITE-695}var cdult = 0;if (me.domain) cdult = 2;if (!me.appLoginURL[me.domain] ) cdult = 3;if (me.cdult !== false) {cdult = me.cdult;}if (cdult == 3) {crossDomainTime = me.crossDomainTime;delete me.appLoginURL[me.domain];}var request = makeRequest(username,password,savestate);request = objMerge( request, {"encoding": "UTF-8","callback": me.name + ".loginCallBack","cdult": cdult, // return crossdomain url list"domain": me.domain,"useticket": me.appLoginURL[me.domain]?1:0,"prelt": preloginTime,"returntype": "TEXT"});var url = (me.loginType & https)?ssoLoginUrl.replace(/^http:/,"https:"):ssoLoginUrl;url = makeURL(url, request);excuteScript(me.scriptId, url, "gb2312");};// login by iframevar loginByIframe = function (username,password,savestate) {createIFrame(me.loginFrameName);var loginForm = createForm(me.loginFormId);var request = makeRequest(username,password,savestate);request["encoding"] = "UTF-8";if (me.crossDomain == false){request["crossdomain"] = 0;}request["prelt"] = preloginTime;if (me.feedBackUrl) {request["url"] = makeURL(me.feedBackUrl, {"framelogin":1, "callback": "parent."+me.name+".feedBackUrlCallBack"});request["returntype"] = "META"; } else {request["callback"] = "parent."+ me.name + ".loginCallBack";request["returntype"] = "IFRAME"; request["setdomain"] = me.setDomain?1:0; }for (var key in me.loginExtraQuery) {if (typeof me.loginExtraQuery[key] == "function") continue;request[key] = me.loginExtraQuery[key]; }for (var name in request) {loginForm.addInput(name,request[name]);}var action = (me.loginType & https)?ssoLoginUrl.replace(/^http:/,"https:"):ssoLoginUrl;action = makeURL(action, objMerge({"client":me.getClientType()},me.loginExtraFlag));loginForm.method = 'post';loginForm.action = action;loginForm.target = me.loginFrameName;var result = true;try{loginForm.submit();} catch(e){removeNode(me.loginFrameName);result = false;}setTimeout(function(){removeNode(loginForm);}, 10);return result;};// 创建Iframevar createIFrame = function (frameName, src) {if (src == null) src = "javascript:false;";removeNode(frameName);var frame = document.createElement('iframe');frame.height = 0;frame.width = 0;frame.style.display = 'none';frame.name = frameName;frame.id = frameName;frame.src = src;appendChild(document.body,frame);window.frames[frameName].name = frameName;return frame;};// 创建form表单var createForm = function (formName,display) {if (display == null) display = 'none';// 确保表单唯一removeNode(formName);var form = document.createElement('form');form.height = 0;form.width = 0;form.style.display = display;form.name = formName;form.id = formName;appendChild(document.body,form);document.forms[formName].name = formName;// 添加一个添加元素的方法form.addInput = function(name,value,type) {if (type == null) type = 'text';var _name = this.getElementsByTagName('input')[name];if (_name ) { // 避免重复添加this.removeChild(_name);}_name = document.createElement('input');this.appendChild(_name);_name.id = name;_name.name = name;_name.type = type;_name.value = value;};return form;};//删除DOM元素var removeNode = function(el){try{if(typeof(el) === 'string') el = me.$(el);el.parentNode.removeChild(el);}catch(e){}};//判断是否为 safari 浏览器var isSafari = function(){var browserName = navigator.userAgent.toLowerCase();return ( (/webkit/i).test(browserName) && !(/chrome/i).test(browserName) );};var appendChild = function(parentObj,element) {parentObj.appendChild(element);};//cookie 函数var getCookie = function( name ) { var Res = eval('/'+ name +'=([^;]+)/').exec(document.cookie);return Res == null ? null : Res[1];};var makeURL = function(url,request) {return url + urlAndChar(url) + httpBuildQuery(request);};var urlAndChar = function(url) { return (/\?/.test(url)?"&":"?");};var urlencode = function(str) {return encodeURIComponent(str);};var urldecode = function(str) {if (str == undefined) return "";var decoded = decodeURIComponent(str);return decoded == "null"?"":decoded;};var httpBuildQuery = function(obj) {if(typeof obj != "object") return "";var arr = new Array();for(var key in obj) {if (typeof obj[key] == "function") continue;arr.push( key + "=" + urlencode(obj[key]));}return arr.join("&");};var parse_str = function(str) {var arr = str.split("&");var arrtmp;var arrResult = {};for(var i = 0; i < arr.length; i++) {arrtmp = arr[i].split("=");arrResult[arrtmp[0]] = urldecode(arrtmp[1]);}return arrResult;};var objMerge = function(obj1,obj2) {for(var item in obj2) {obj1[item] = obj2[item];}return obj1;};// 获取元素对象this.$ = function (id) {return document.getElementById(id);};};/* * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined * in FIPS PUB 180-1 * Version 2.1-BETA Copyright Paul Johnston 2000 - 2002. * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for details. */ var sinaSSOEncoder = sinaSSOEncoder || {};(function(){ /* * Configurable variables. You may need to tweak these to be compatible with * the server-side, but the defaults work in most cases. */ var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */ var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */ /* * These are the functions you'll usually want to call * They take string arguments and return either hex or base-64 encoded strings */ this.hex_sha1 = function(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}; /* * Calculate the SHA-1 of an array of big-endian words, and a bit length */ var core_sha1 = function(x, len) { /* append padding */ x[len >> 5] |= 0x80 << (24 - len % 32); x[((len + 64 >> 9) << 4) + 15] = len; var w = Array(80); var a = 1732584193; var b = -271733879; var c = -1732584194; var d = 271733878; var e = -1009589776; for(var i = 0; i < x.length; i += 16) { var olda = a; var oldb = b; var oldc = c; var oldd = d; var olde = e; for(var j = 0; j < 80; j++) { if(j < 16) w[j] = x[i + j]; else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1); var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)), safe_add(safe_add(e, w[j]), sha1_kt(j))); e = d; d = c; c = rol(b, 30); b = a; a = t; } a = safe_add(a, olda); b = safe_add(b, oldb); c = safe_add(c, oldc); d = safe_add(d, oldd); e = safe_add(e, olde); } return Array(a, b, c, d, e); }; /* * Perform the appropriate triplet combination function for the current * iteration */ var sha1_ft = function(t, b, c, d) { if(t < 20) return (b & c) | ((~b) & d); if(t < 40) return b ^ c ^ d; if(t < 60) return (b & c) | (b & d) | (c & d); return b ^ c ^ d; }; /* * Determine the appropriate additive constant for the current iteration */ var sha1_kt = function(t) { return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 : (t < 60) ? -1894007588 : -899497514; }; /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ var safe_add = function(x, y) { var lsw = (x & 0xFFFF) + (y & 0xFFFF); var msw = (x >> 16) + (y >> 16) + (lsw >> 16); return (msw << 16) | (lsw & 0xFFFF); }; /* * Bitwise rotate a 32-bit number to the left. */ var rol = function(num, cnt) { return (num << cnt) | (num >>> (32 - cnt)); }; /* * Convert an 8-bit or 16-bit string to an array of big-endian words * In 8-bit function, characters >255 have their hi-byte silently ignored. */ var str2binb = function(str) { var bin = Array(); var mask = (1 << chrsz) - 1; for(var i = 0; i < str.length * chrsz; i += chrsz) bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32); return bin; }; /* * Convert an array of big-endian words to a hex string. */ var binb2hex = function(binarray) { var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef"; var str = ""; for(var i = 0; i < binarray.length * 4; i++) { str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) + hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF); } return str; }; /* * Convert a string into a base 64 encoded string */ this.base64 = {encode:function(input) {input = "" + input; // Convert to string for encodeif (input == "") return ""; var output = '';var chr1, chr2, chr3 = '';var enc1, enc2, enc3, enc4 = '';var i = 0;do {chr1 = input.charCodeAt(i++);chr2 = input.charCodeAt(i++);chr3 = input.charCodeAt(i++);enc1 = chr1 >> 2;enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);enc4 = chr3 & 63;if (isNaN(chr2)){enc3 = enc4 = 64;} else if (isNaN(chr3)){enc4 = 64;}output = output+this._keys.charAt(enc1)+this._keys.charAt(enc2)+this._keys.charAt(enc3)+this._keys.charAt(enc4);chr1 = chr2 = chr3 = '';enc1 = enc2 = enc3 = enc4 = '';} while (i < input.length);return output;},_keys: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=' };}).call(sinaSSOEncoder);//RSA;(function(){ /********************* jsbn.js start ************************/// Copyright (c) 2005 Tom Wu// All Rights Reserved.// See "LICENSE" for details.// Basic JavaScript BN library - subset useful for RSA encryption.// Bits per digitvar dbits;// JavaScript engine analysisvar canary = 0xdeadbeefcafe;var j_lm = ((canary&0xffffff)==0xefcafe);// (public) Constructorfunction BigInteger(a,b,c) { if(a != null)if("number" == typeof a) this.fromNumber(a,b,c);else if(b == null && "string" != typeof a) this.fromString(a,256);else this.fromString(a,b);}// return new, unset BigIntegerfunction nbi() { return new BigInteger(null); }// am: Compute w_j += (x*this_i), propagate carries,// c is initial carry, returns final carry.// c < 3*dvalue, x < 2*dvalue, this_i < dvalue// We need to select the fastest one that works in this environment.// am1: use a single mult and divide to get the high bits,// max digit bits should be 26 because// max internal value = 2*dvalue^2-2*dvalue (< 2^53)function am1(i,x,w,j,c,n) { while(--n >= 0) {var v = x*this[i++]+w[j]+c;c = Math.floor(v/0x4000000);w[j++] = v&0x3ffffff; } return c;}// am2 avoids a big mult-and-extract completely.// Max digit bits should be <= 30 because we do bitwise ops// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)function am2(i,x,w,j,c,n) { var xl = x&0x7fff, xh = x>>15; while(--n >= 0) {var l = this[i]&0x7fff;var h = this[i++]>>15;var m = xh*l+h*xl;l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);w[j++] = l&0x3fffffff; } return c;}// Alternately, set max digit bits to 28 since some// browsers slow down when dealing with 32-bit numbers.function am3(i,x,w,j,c,n) { var xl = x&0x3fff, xh = x>>14; while(--n >= 0) {var l = this[i]&0x3fff;var h = this[i++]>>14;var m = xh*l+h*xl;l = xl*l+((m&0x3fff)<<14)+w[j]+c;c = (l>>28)+(m>>14)+xh*h;w[j++] = l&0xfffffff; } return c;}if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) { BigInteger.prototype.am = am2; dbits = 30;}else if(j_lm && (navigator.appName != "Netscape")) { BigInteger.prototype.am = am1; dbits = 26;}else { // Mozilla/Netscape seems to prefer am3 BigInteger.prototype.am = am3; dbits = 28;}BigInteger.prototype.DB = dbits;BigInteger.prototype.DM = ((1<<dbits)-1);BigInteger.prototype.DV = (1<<dbits);var BI_FP = 52;BigInteger.prototype.FV = Math.pow(2,BI_FP);BigInteger.prototype.F1 = BI_FP-dbits;BigInteger.prototype.F2 = 2*dbits-BI_FP;// Digit conversionsvar BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";var BI_RC = new Array();var rr,vv;rr = "0".charCodeAt(0);for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;rr = "a".charCodeAt(0);for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;rr = "A".charCodeAt(0);for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;function int2char(n) { return BI_RM.charAt(n); }function intAt(s,i) { var c = BI_RC[s.charCodeAt(i)]; return (c==null)?-1:c;}// (protected) copy this to rfunction bnpCopyTo(r) { for(var i = this.t-1; i >= 0; --i) r[i] = this[i]; r.t = this.t; r.s = this.s;}// (protected) set from integer value x, -DV <= x < DVfunction bnpFromInt(x) { this.t = 1; this.s = (x<0)?-1:0; if(x > 0) this[0] = x; else if(x < -1) this[0] = x+DV; else this.t = 0;}// return bigint initialized to valuefunction nbv(i) { var r = nbi(); r.fromInt(i); return r; }// (protected) set from string and radixfunction bnpFromString(s,b) { var k; if(b == 16) k = 4; else if(b == 8) k = 3; else if(b == 256) k = 8; // byte array else if(b == 2) k = 1; else if(b == 32) k = 5; else if(b == 4) k = 2; else { this.fromRadix(s,b); return; } this.t = 0; this.s = 0; var i = s.length, mi = false, sh = 0; while(--i >= 0) {var x = (k==8)?s[i]&0xff:intAt(s,i);if(x < 0) { if(s.charAt(i) == "-") mi = true; continue;}mi = false;if(sh == 0) this[this.t++] = x;else if(sh+k > this.DB) { this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh; this[this.t++] = (x>>(this.DB-sh));}else this[this.t-1] |= x<<sh;sh += k;if(sh >= this.DB) sh -= this.DB; } if(k == 8 && (s[0]&0x80) != 0) {this.s = -1;if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh; } this.clamp(); if(mi) BigInteger.ZERO.subTo(this,this);}// (protected) clamp off excess high wordsfunction bnpClamp() { var c = this.s&this.DM; while(this.t > 0 && this[this.t-1] == c) --this.t;}// (public) return string representation in given radixfunction bnToString(b) { if(this.s < 0) return "-"+this.negate().toString(b); var k; if(b == 16) k = 4; else if(b == 8) k = 3; else if(b == 2) k = 1; else if(b == 32) k = 5; else if(b == 4) k = 2; else return this.toRadix(b); var km = (1<<k)-1, d, m = false, r = "", i = this.t; var p = this.DB-(i*this.DB)%k; if(i-- > 0) {if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }while(i >= 0) { if(p < k) {d = (this[i]&((1<<p)-1))<<(k-p);d |= this[--i]>>(p+=this.DB-k); } else {d = (this[i]>>(p-=k))&km;if(p <= 0) { p += this.DB; --i; } } if(d > 0) m = true; if(m) r += int2char(d);} } return m?r:"0";}// (public) -thisfunction bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }// (public) |this|function bnAbs() { return (this.s<0)?this.negate():this; }// (public) return + if this > a, - if this < a, 0 if equalfunction bnCompareTo(a) { var r = this.s-a.s; if(r != 0) return r; var i = this.t; r = i-a.t; if(r != 0) return r; while(--i >= 0) if((r=this[i]-a[i]) != 0) return r; return 0;}// returns bit length of the integer xfunction nbits(x) { var r = 1, t; if((t=x>>>16) != 0) { x = t; r += 16; } if((t=x>>8) != 0) { x = t; r += 8; } if((t=x>>4) != 0) { x = t; r += 4; } if((t=x>>2) != 0) { x = t; r += 2; } if((t=x>>1) != 0) { x = t; r += 1; } return r;}// (public) return the number of bits in "this"function bnBitLength() { if(this.t <= 0) return 0; return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));}// (protected) r = this << n*DBfunction bnpDLShiftTo(n,r) { var i; for(i = this.t-1; i >= 0; --i) r[i+n] = this[i]; for(i = n-1; i >= 0; --i) r[i] = 0; r.t = this.t+n; r.s = this.s;}// (protected) r = this >> n*DBfunction bnpDRShiftTo(n,r) { for(var i = n; i < this.t; ++i) r[i-n] = this[i]; r.t = Math.max(this.t-n,0); r.s = this.s;}// (protected) r = this << nfunction bnpLShiftTo(n,r) { var bs = n%this.DB; var cbs = this.DB-bs; var bm = (1<<cbs)-1; var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i; for(i = this.t-1; i >= 0; --i) {r[i+ds+1] = (this[i]>>cbs)|c;c = (this[i]&bm)<<bs; } for(i = ds-1; i >= 0; --i) r[i] = 0; r[ds] = c; r.t = this.t+ds+1; r.s = this.s; r.clamp();}// (protected) r = this >> nfunction bnpRShiftTo(n,r) { r.s = this.s; var ds = Math.floor(n/this.DB); if(ds >= this.t) { r.t = 0; return; } var bs = n%this.DB; var cbs = this.DB-bs; var bm = (1<<bs)-1; r[0] = this[ds]>>bs; for(var i = ds+1; i < this.t; ++i) {r[i-ds-1] |= (this[i]&bm)<<cbs;r[i-ds] = this[i]>>bs; } if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs; r.t = this.t-ds; r.clamp();}// (protected) r = this - afunction bnpSubTo(a,r) { var i = 0, c = 0, m = Math.min(a.t,this.t); while(i < m) {c += this[i]-a[i];r[i++] = c&this.DM;c >>= this.DB; } if(a.t < this.t) {c -= a.s;while(i < this.t) { c += this[i]; r[i++] = c&this.DM; c >>= this.DB;}c += this.s; } else {c += this.s;while(i < a.t) { c -= a[i]; r[i++] = c&this.DM; c >>= this.DB;}c -= a.s; } r.s = (c<0)?-1:0; if(c < -1) r[i++] = this.DV+c; else if(c > 0) r[i++] = c; r.t = i; r.clamp();}// (protected) r = this * a, r != this,a (HAC 14.12)// "this" should be the larger one if appropriate.function bnpMultiplyTo(a,r) { var x = this.abs(), y = a.abs(); var i = x.t; r.t = i+y.t; while(--i >= 0) r[i] = 0; for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t); r.s = 0; r.clamp(); if(this.s != a.s) BigInteger.ZERO.subTo(r,r);}// (protected) r = this^2, r != this (HAC 14.16)function bnpSquareTo(r) { var x = this.abs(); var i = r.t = 2*x.t; while(--i >= 0) r[i] = 0; for(i = 0; i < x.t-1; ++i) {var c = x.am(i,x[i],r,2*i,0,1);if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) { r[i+x.t] -= x.DV; r[i+x.t+1] = 1;} } if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1); r.s = 0; r.clamp();}// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)// r != q, this != m. q or r may be null.function bnpDivRemTo(m,q,r) { var pm = m.abs(); if(pm.t <= 0) return; var pt = this.abs(); if(pt.t < pm.t) {if(q != null) q.fromInt(0);if(r != null) this.copyTo(r);return; } if(r == null) r = nbi(); var y = nbi(), ts = this.s, ms = m.s; var nsh = this.DB-nbits(pm[pm.t-1]);// normalize modulus if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); } else { pm.copyTo(y); pt.copyTo(r); } var ys = y.t; var y0 = y[ys-1]; if(y0 == 0) return; var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0); var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2; var i = r.t, j = i-ys, t = (q==null)?nbi():q; y.dlShiftTo(j,t); if(r.compareTo(t) >= 0) {r[r.t++] = 1;r.subTo(t,r); } BigInteger.ONE.dlShiftTo(ys,t); t.subTo(y,y);// "negative" y so we can replace sub with am later while(y.t < ys) y[y.t++] = 0; while(--j >= 0) {// Estimate quotient digitvar qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) {// Try it out y.dlShiftTo(j,t); r.subTo(t,r); while(r[i] < --qd) r.subTo(t,r);} } if(q != null) {r.drShiftTo(ys,q);if(ts != ms) BigInteger.ZERO.subTo(q,q); } r.t = ys; r.clamp(); if(nsh > 0) r.rShiftTo(nsh,r);// Denormalize remainder if(ts < 0) BigInteger.ZERO.subTo(r,r);}// (public) this mod afunction bnMod(a) { var r = nbi(); this.abs().divRemTo(a,null,r); if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r); return r;}// Modular reduction using "classic" algorithmfunction Classic(m) { this.m = m; }function cConvert(x) { if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m); else return x;}function cRevert(x) { return x; }function cReduce(x) { x.divRemTo(this.m,null,x); }function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }Classic.prototype.convert = cConvert;Classic.prototype.revert = cRevert;Classic.prototype.reduce = cReduce;Classic.prototype.mulTo = cMulTo;Classic.prototype.sqrTo = cSqrTo;// (protected) return "-1/this % 2^DB"; useful for Mont. reduction// justification:// xy == 1 (mod m)// xy = 1+km// xy(2-xy) = (1+km)(1-km)// x[y(2-xy)] = 1-k^2m^2// x[y(2-xy)] == 1 (mod m^2)// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.// JS multiply "overflows" differently from C/C++, so care is needed here.function bnpInvDigit() { if(this.t < 1) return 0; var x = this[0]; if((x&1) == 0) return 0; var y = x&3;// y == 1/x mod 2^2 y = (y*(2-(x&0xf)*y))&0xf;// y == 1/x mod 2^4 y = (y*(2-(x&0xff)*y))&0xff;// y == 1/x mod 2^8 y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff;// y == 1/x mod 2^16 // last step - calculate inverse mod DV directly; // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints y = (y*(2-x*y%this.DV))%this.DV;// y == 1/x mod 2^dbits // we really want the negative inverse, and -DV < y < DV return (y>0)?this.DV-y:-y;}// Montgomery reductionfunction Montgomery(m) { this.m = m; this.mp = m.invDigit(); this.mpl = this.mp&0x7fff; this.mph = this.mp>>15; this.um = (1<<(m.DB-15))-1; this.mt2 = 2*m.t;}// xR mod mfunction montConvert(x) { var r = nbi(); x.abs().dlShiftTo(this.m.t,r); r.divRemTo(this.m,null,r); if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r); return r;}// x/R mod mfunction montRevert(x) { var r = nbi(); x.copyTo(r); this.reduce(r); return r;}// x = x/R mod m (HAC 14.32)function montReduce(x) { while(x.t <= this.mt2)// pad x so am has enough room laterx[x.t++] = 0; for(var i = 0; i < this.m.t; ++i) {// faster way of calculating u0 = x[i]*mp mod DVvar j = x[i]&0x7fff;var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;// use am to combine the multiply-shift-add into one callj = i+this.m.t;x[j] += this.m.am(0,u0,x,i,0,this.m.t);// propagate carrywhile(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; } } x.clamp(); x.drShiftTo(this.m.t,x); if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);}// r = "x^2/R mod m"; x != rfunction montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }// r = "xy/R mod m"; x,y != rfunction montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }Montgomery.prototype.convert = montConvert;Montgomery.prototype.revert = montRevert;Montgomery.prototype.reduce = montReduce;Montgomery.prototype.mulTo = montMulTo;Montgomery.prototype.sqrTo = montSqrTo;// (protected) true iff this is evenfunction bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)function bnpExp(e,z) { if(e > 0xffffffff || e < 1) return BigInteger.ONE; var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1; g.copyTo(r); while(--i >= 0) {z.sqrTo(r,r2);if((e&(1<<i)) > 0) z.mulTo(r2,g,r);else { var t = r; r = r2; r2 = t; } } return z.revert(r);}// (public) this^e % m, 0 <= e < 2^32function bnModPowInt(e,m) { var z; if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m); return this.exp(e,z);}// protectedBigInteger.prototype.copyTo = bnpCopyTo;BigInteger.prototype.fromInt = bnpFromInt;BigInteger.prototype.fromString = bnpFromString;BigInteger.prototype.clamp = bnpClamp;BigInteger.prototype.dlShiftTo = bnpDLShiftTo;BigInteger.prototype.drShiftTo = bnpDRShiftTo;BigInteger.prototype.lShiftTo = bnpLShiftTo;BigInteger.prototype.rShiftTo = bnpRShiftTo;BigInteger.prototype.subTo = bnpSubTo;BigInteger.prototype.multiplyTo = bnpMultiplyTo;BigInteger.prototype.squareTo = bnpSquareTo;BigInteger.prototype.divRemTo = bnpDivRemTo;BigInteger.prototype.invDigit = bnpInvDigit;BigInteger.prototype.isEven = bnpIsEven;BigInteger.prototype.exp = bnpExp;// publicBigInteger.prototype.toString = bnToString;BigInteger.prototype.negate = bnNegate;BigInteger.prototype.abs = bnAbs;BigInteger.prototype.compareTo = bnCompareTo;BigInteger.prototype.bitLength = bnBitLength;BigInteger.prototype.mod = bnMod;BigInteger.prototype.modPowInt = bnModPowInt;// "constants"BigInteger.ZERO = nbv(0);BigInteger.ONE = nbv(1);/********************* jsbn.js end ************************//********************* prng4.js start ************************/// prng4.js - uses Arcfour as a PRNGfunction Arcfour() { this.i = 0; this.j = 0; this.S = new Array();}// Initialize arcfour context from key, an array of ints, each from [0..255]function ARC4init(key) { var i, j, t; for(i = 0; i < 256; ++i)this.S[i] = i; j = 0; for(i = 0; i < 256; ++i) {j = (j + this.S[i] + key[i % key.length]) & 255;t = this.S[i];this.S[i] = this.S[j];this.S[j] = t; } this.i = 0; this.j = 0;}function ARC4next() { var t; this.i = (this.i + 1) & 255; this.j = (this.j + this.S[this.i]) & 255; t = this.S[this.i]; this.S[this.i] = this.S[this.j]; this.S[this.j] = t; return this.S[(t + this.S[this.i]) & 255];}Arcfour.prototype.init = ARC4init;Arcfour.prototype.next = ARC4next;// Plug in your RNG constructor herefunction prng_newstate() { return new Arcfour();}// Pool size must be a multiple of 4 and greater than 32.// An array of bytes the size of the pool will be passed to init()var rng_psize = 256;/********************* prng4.js end ************************//********************* rng.js start ************************/// Random number generator - requires a PRNG backend, e.g. prng4.js// For best results, put code like// <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>// in your main HTML document.var rng_state;var rng_pool;var rng_pptr;// Mix in a 32-bit integer into the poolfunction rng_seed_int(x) { rng_pool[rng_pptr++] ^= x & 255; rng_pool[rng_pptr++] ^= (x >> 8) & 255; rng_pool[rng_pptr++] ^= (x >> 16) & 255; rng_pool[rng_pptr++] ^= (x >> 24) & 255; if(rng_pptr >= rng_psize) rng_pptr -= rng_psize;}// Mix in the current time (w/milliseconds) into the poolfunction rng_seed_time() { rng_seed_int(new Date().getTime());}// Initialize the pool with junk if needed.if(rng_pool == null) { rng_pool = new Array(); rng_pptr = 0; var t; if(navigator.appName == "Netscape" && navigator.appVersion < "5" && window.crypto && typeof(window.crypto.random) === 'function') {// Extract entropy (256 bits) from NS4 RNG if availablevar z = window.crypto.random(32);for(t = 0; t < z.length; ++t) rng_pool[rng_pptr++] = z.charCodeAt(t) & 255; } while(rng_pptr < rng_psize) { // extract some randomness from Math.random()t = Math.floor(65536 * Math.random());rng_pool[rng_pptr++] = t >>> 8;rng_pool[rng_pptr++] = t & 255; } rng_pptr = 0; rng_seed_time(); //rng_seed_int(window.screenX); //rng_seed_int(window.screenY);}function rng_get_byte() { if(rng_state == null) {rng_seed_time();rng_state = prng_newstate();rng_state.init(rng_pool);for(rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) rng_pool[rng_pptr] = 0;rng_pptr = 0;//rng_pool = null; } // TODO: allow reseeding after first request return rng_state.next();}function rng_get_bytes(ba) { var i; for(i = 0; i < ba.length; ++i) ba[i] = rng_get_byte();}function SecureRandom() {}SecureRandom.prototype.nextBytes = rng_get_bytes;/********************* rng.js end ************************//********************* rsa.js start ************************/// Depends on jsbn.js and rng.js// Version 1.1: support utf-8 encoding in pkcs1pad2// convert a (hex) string to a bignum objectfunction parseBigInt(str,r) { return new BigInteger(str,r);}function linebrk(s,n) { var ret = ""; var i = 0; while(i + n < s.length) {ret += s.substring(i,i+n) + "\n";i += n; } return ret + s.substring(i,s.length);}function byte2Hex(b) { if(b < 0x10)return "0" + b.toString(16); elsereturn b.toString(16);}// PKCS#1 (type 2, random) pad input string s to n bytes, and return a bigintfunction pkcs1pad2(s,n) { if(n < s.length + 11) { // TODO: fix for utf-8alert("Message too long for RSA");return null; } var ba = new Array(); var i = s.length - 1; while(i >= 0 && n > 0) {var c = s.charCodeAt(i--);if(c < 128) { // encode using utf-8 ba[--n] = c;}else if((c > 127) && (c < 2048)) { ba[--n] = (c & 63) | 128; ba[--n] = (c >> 6) | 192;}else { ba[--n] = (c & 63) | 128; ba[--n] = ((c >> 6) & 63) | 128; ba[--n] = (c >> 12) | 224;} } ba[--n] = 0; var rng = new SecureRandom(); var x = new Array(); while(n > 2) { // random non-zero padx[0] = 0;while(x[0] == 0) rng.nextBytes(x);ba[--n] = x[0]; } ba[--n] = 2; ba[--n] = 0; return new BigInteger(ba);}// "empty" RSA key constructorfunction RSAKey() { this.n = null; this.e = 0; this.d = null; this.p = null; this.q = null; this.dmp1 = null; this.dmq1 = null; this.coeff = null;}// Set the public key fields N and e from hex stringsfunction RSASetPublic(N,E) { if(N != null && E != null && N.length > 0 && E.length > 0) {this.n = parseBigInt(N,16);this.e = parseInt(E,16); } elsealert("Invalid RSA public key");}// Perform raw public operation on "x": return x^e (mod n)function RSADoPublic(x) { return x.modPowInt(this.e, this.n);}// Return the PKCS#1 RSA encryption of "text" as an even-length hex stringfunction RSAEncrypt(text) { var m = pkcs1pad2(text,(this.n.bitLength()+7)>>3); if(m == null) return null; var c = this.doPublic(m); if(c == null) return null; var h = c.toString(16); if((h.length & 1) == 0) return h; else return "0" + h;}// Return the PKCS#1 RSA encryption of "text" as a Base64-encoded string//function RSAEncryptB64(text) {// var h = this.encrypt(text);// if(h) return hex2b64(h); else return null;//}// protectedRSAKey.prototype.doPublic = RSADoPublic;// publicRSAKey.prototype.setPublic = RSASetPublic;RSAKey.prototype.encrypt = RSAEncrypt;//RSAKey.prototype.encrypt_b64 = RSAEncryptB64;//暴露RSAKeythis.RSAKey = RSAKey;//example://var rsa = new RSAKey();//rsa.setPublic(encode_key, key_plus);//password = rsa.encrypt(password);}).call(sinaSSOEncoder);sinaSSOController = new SSOController();sinaSSOController.init();var argv = process.argv.splice(2);var pubkey = argv[0],servertime = argv[1],nonce = argv[2],password = argv[3];var RSAKey = new sinaSSOEncoder.RSAKey();RSAKey.setPublic(pubkey, '10001');password = RSAKey.encrypt([servertime, nonce].join("\t") + "\n" + password);console.log(password);process.exit();
执行命令格式:nodejs sso.js pubkey servertime nonce pwd
执行结果:
joyatonce@bananabook:~/# nodejs sso.js EB2A38568661887FA180BDDB5CABD5F21C7BFD59C090CB2D245A87AC253062882729293E5506350508E7F9AA3BB77F4333231490F915F6D63C55FE2F08A49B353F444AD3993CACC02DB784ABBB8E42A9B1BBFFFB38BE18D78E87A0E41B9B8F73A928EE0CCEE1F6739884B9777E4FE9E88A1BBE495927AC4A799B3181D6442443 1468637370 ERT5SI 1234566ccb7ac7a3759dda47798b7dc5c58346aff915d982e931f9a65370e4cdcea8db59c17afb1cb942529a589279aade599fbcef2032e2304f7c0d75d2d66148a43bb9070123b75920e6eaeba095d5bf8c60789e137c1fa5defffc0f3bb016d9eb4a0b06e6ca321aac84c406054cd97287b9a8f1210f51a86c3de31cf7fb5c56abf2
^_^
0 0
- 【旧代码整理】Nodejs的另类用法
- 【旧代码整理】一个PHP操作mysql的class类
- 【旧代码整理】uri路由处理的重要组成部分 Model_Route
- 【旧代码整理】我是这么用Redis的,哈哈哈
- #define 的另类用法
- WPE的另类用法
- WPE的另类用法
- overflow的另类用法
- RPM的另类用法
- new的另类用法
- printf的另类用法
- DataTable 的另类用法
- Decal的另类用法
- printf的另类用法
- 与旧代码的接口(C++中C_str()的用法)
- 【旧资料整理】firefox addEventListener用法
- 【旧代码整理】uri路由处理部分
- 【旧代码整理】PHP生成二维码
- canvas实现擦除动画
- IE双击不能打开没反应只能用管理员权限运行怎么办
- 链式编程思想
- SE for Android 系列之整体概要(一)
- Android Button 大写
- 【旧代码整理】Nodejs的另类用法
- 自定义边缘拖动阴影的颜色
- UVA 1025A Spy in the Metro (简单DP)
- AJAX 跨域请求 - JSONP获取JSON数据
- Android RecyclerView 使用完全解析 体验艺术般的控件
- 常用人脸数据库
- CubieBoard2串口
- appcan开发经验总结
- Guava使用总结