js怎么实现hmacsha256_怎么调用JS中的CryptoJS.HmacSHA256加密方法啊?好像没有集成到httphelper框架中...

这段代码展示了如何在JavaScript中使用CryptoJS库进行HmacSHA256加密,用于登录过程。在登录请求中,密码经过HmacSHA256加密并与特定密钥结合,然后将加密后的密码发送到服务器。
摘要由CSDN通过智能技术生成

function login2load(){

$('#loginButton').attr("disabled",true);

var dataCenter = new $.NUI_DataCenter();

var login_username= $('#login_username').val();

var login_password= $('#login_password').val();

//    if (login_password == defPwd) {

//        alert("当前密码为初始密码,请修改密码");

        window.location = cpadGlobal.WEB_APP_NAME + "/changePwd.html";

//        return;

//    }

$('#login_password').val("");

dataCenter.putParameter("userName",login_username);

//dataCenter.putParameter("userPassword",login_password);

dataCenter.putParameter("userPassword",CryptoJS.HmacSHA256(login_password, "123456").toString(CryptoJS.enc.Hex));

var parm=JSON.stringify(dataCenter);

$.ajax({

type: "post",

url: "http://"+window.location.host+cpadGlobal.WEB_APP_NAME+"/login",

processData: false,

data: parm,

contentType:"application/x-www-form-urlencoded; charset=utf-8",

error:function(dc, textStatus, errorThrown){

alert(dc.responseJSON.header.message.detail);

},

success:  function(dc){

if (dc.header.code == 0) {

//                       alert(dc.header.message.detail);

document.getElementById("msg").innerHTML = dc.header.message.detail;

return ;

} else {

document.getElementById("msg").innerHTML = "";

}

$.set_global("token",dc.body.parameters.AccessToken.token);

$.set_global("user",dc.body.parameters.AccessToken.account);

$.set_global("sysdate",dc.body.parameters.SYSDATE);

$.set_global("AccInfo",dc.body.parameters.AccInfo);

var saveConfig = {"option":dc.body.parameters.userCompAuthority.aar099, "flag":dc.body.parameters.userCompAuthority.aar098};

$.set_global("saveConfig",saveConfig);

var rootmenu= $.extend(new $.NUI_DataStore(), dc.body.dataStores.rootMenu);

var submenu= $.extend(new $.NUI_DataStore(), dc.body.dataStores.subMenu);

if(rootmenu.getRowCount()>0){

rootMenuStore=rootmenu.getRows();

basestore=submenu.getRows();

$.each(basestore,function(k,v){

v.id=v.ID;

v.label=v.LABEL;

v.rootId=v.ROOTID;

v.parentId=v.PARENTID;

v.location=v.LOCATION?cpadGlobal.WEB_APP_NAME+v.LOCATION:v.LOCATION;

});

$.set_global("basestore",basestore);

$.set_global("rootMenuStore",rootMenuStore);

(function initStatePathMapping(source){

var securityAjax = function(config){

var microTime = new Date().getTime(),

digest = function (url, method, params, data, microTime) {

var content = method + ':' + url + ':' + data + ':' + microTime,

digest = CryptoJS.HmacSHA256(content, $.get_global("token")).toString(CryptoJS.enc.Hex);

return digest;

},

headers = {};

headers['X-USER'] = $.get_global("user");

headers['X-MICRO-TIME'] = microTime;

headers['X-HMAC-HASH'] = digest(config["url"], config["type"]||"get", null, config["data"]||"", microTime);

config["headers"] = config["headers"] || {};

angular.extend(config["headers"], headers);

var result = $.ajax(config);

return result.responseText;

},

StatePathMapping = {},

extraPageJsonStr = securityAjax({url:cpadGlobal.WEB_APP_NAME+"/public/mainApp/privatePage.json", async:false});

extraPageJsonObj = angular.fromJson(extraPageJsonStr);

angular.forEach(extraPageJsonObj, function(config){

config.location = cpadGlobal.WEB_APP_NAME + config.location;

});

basestore.push.apply(basestore, extraPageJsonObj);

if(source){

for( var i=0,loopCounter=source.length; i

var href = source[i]["location"];

href = href && href.substring(href.indexOf(cpadGlobal.WEB_APP_NAME,0)+cpadGlobal.WEB_APP_NAME.length+1, href.length);

StatePathMapping[source[i]["id"]] = {};

StatePathMapping[source[i]["id"]]["templateUrl"] = href;

}

angular.module('NUI_MainFrameWork').config([ '$stateProvider', function($stateProvider) {

$stateProvider.state('myapp',{

url   : '',

views : StatePathMapping

});

} ]);

}

})(basestore);

if($('body').injector()){

}else{

angular.bootstrap($('body'),["NUI_MainFrameWork"]);

}

createRootMenuList();

$("#layLogin").fadeOut("slow");

$("#layUpdatePwd").fadeOut("slow");

//initStatePathMapping(basestore);

//                    var rows=menu.getRows();

//                    $.each(rows,function(){

//

//                    });

$("#loginUsrInfo").text("当前用户:"+dc.body.parameters.AccInfo.usrname);

if(saveConfig.option || saveConfig.flag)

alert("目前尚未开通保存功能权限,请联系省办开通。");

}

else {

alert("该用户授权菜单为空");

}

$('#loginButton').removeAttr("disabled");

}

});

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值