• postgrelsql base64加密,JS base64解密


     项目中做云桌面对接,需要在项目中查出用户的明文密码,拼接到云桌面登陆地址中,防止明文传输,做了base64加密解密,防止小白黑客盗取用户密码。

    postgrelsql base64加密SQL语句:

    查询用户证件号码后四位,base64加密的密码

     SELECT 
    	substr(idno, length(idno) - 3) idno,
    	ENCODE(cast(password as bytea),'base64') xm
    FROM security.oauth_user 
    WHERE id  = #{USERPK}
    

     

    JS代码:

    模拟post请求,云桌面需要Post请求模拟登陆,其他系统以get方式

     /*
         *功能: 模拟form表单的提交
         *参数: URL 跳转地址 
         *     PARAMTERS 参数
         *     METHOD post或者get
         */
         function postUrl(URL, PARAMTERS,METHOD) {
             //创建form表单
             var temp_form = document.createElement("form");
             temp_form.action = URL;
             //如需打开新窗口,form的target属性要设置为'_blank'
             temp_form.target = "_blank";
             temp_form.method = METHOD;
             temp_form.style.display = "none";
             //添加参数
             for (var item in PARAMTERS) {
                 var opt = document.createElement("textarea");
                 opt.name = PARAMTERS[item].name;
                 opt.value = PARAMTERS[item].value;
                 temp_form.appendChild(opt);
             }
             document.body.appendChild(temp_form);
             //提交数据
             temp_form.submit();
         }
     //打开APP链接
         $scope.openUrl = function(app){
             var parames = new Array();
             var method = "get";
             if(app.name == "云桌面" || app.id == "ebe6132d-cbcc-4349-aa36-5810fa55c048"){
                var username = $scope.userInfo.pinyin + $scope.userInfo.idno;
                var pwd = window.atob($scope.userInfo.pwd);
                parames.push({ name: "login", value: username});
                parames.push({ name: "passwd", value: pwd});
                method = "post";
             }
             
             postUrl(app.url, parames,method);
         }

    补充:

    从IE10+浏览器开始,所有浏览器就原生提供了Base64编码、解码方法,不仅可以用于浏览器环境,Service Worker环境也可以使用。
    方法名就是 atob 和 btoa ,具体语法如下:

    window.btoa('china is so nb') // 编码
    "Y2hpbmEgaXMgc28gbmI="
    window.atob("Y2hpbmEgaXMgc28gbmI=") // 解码
    "china is so nb"

    开源的base64.js(https://github.com/dankogai/js-base64) ,使用很简单,浏览器引入该JS文件,然后Base64编码这样:

    Base64.encode('china is so nb'); // 编码
    "Y2hpbmEgaXMgc28gbmI="
    Base64.decode("Y2hpbmEgaXMgc28gbmI="); // 解码
    'china is so nb'
  • 相关阅读:
    LeetCode 1049. Last Stone Weight II
    LeetCode 56. Merge Intervals
    LeetCode 494. Target Sum
    LeetCode 763. Partition Labels
    LeetCode 343. Integer Break
    LeetCode 435. Nonoverlapping Intervals
    PHP71yum安装
    docker容器资源配额
    神经网络基本结构
    神经网络基础
  • 原文地址:https://www.cnblogs.com/remember-forget/p/11811792.html
Copyright © 2020-2023  润新知