pythonrsa加密与sha256加密

这个比较有意思,不过我前端不太熟悉,js也是二懂二懂的。

登录校验

最近的业务涉及到这一块,这边分析前端的源代码、发现涉及两种登录方式。

首先在这边找前端源代码

sha256

javascript 复制代码
xxxx: function() {

     var t = a("6c27").sha256;
     l["a"].post("login/xxxx", {
         userCode: this.loginForm.usercode
     }).then((function(a) {
         var i = a.data;
         i && i.data && !i.data.firstLoginFlag && i.data.hash && i.data.ts ? (e.shaStr = t(i.data.hash + i.data.ts),
         e.sildeSuccessCallBack(!1)) : e.isShow = !0
     }
     )).catch((function(t) {
         e.loginText = "登 录",
         e.loading = !1,
         e.$message({
             message: "网络错误,请刷新重试",
             type: "warning"
         }),
         console.log(t)
     }
     ))
 },

首先分析后端接口,再从前端源代码中搜索对应的urllogin/xxxx,这里是通过链接获取会话id,与时间timestamp,相加,加了后进行sha256加密。t(i.data.hash + i.data.ts)

python 复制代码
import hashlib
def sha256_hash(text):
    if not isinstance(text, bytes):
        text=text.encode('utf-8')
    hash_object = hashlib.sha256()
    hash_object.update(text)
    hex_dig = hash_object.hexdigest()
    return hex_dig

RSA加密

javascript 复制代码
Object(l["a"])({
    method: "post",
    url: "/login/xxxx"
}).then((function(s) {
    if (0 === s.data.status) {
        var p = o.a.KEYUTIL.getKey(s.data.data)
          , m = o.a.KJUR.crypto.Cipher.encrypt(u, p)
          , v = o.a.hextob64(m)
        };
}

rsa的一个特点是每次加密结果都不一样,因为有随机的padding,这里可以看到加密是先获取公钥,再加密,最后转为base64。

python 复制代码
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
import base64
def encrpt(password, public_key):
    rsakey = RSA.importKey(public_key)
    cipher = Cipher_pksc1_v1_5.new(rsakey)
    cipher_text = base64.b64encode(cipher.encrypt(password.encode())).decode()
    # cipher_text = sha256_hash(cipher.encrypt(password.encode()))
    return cipher_text
相关推荐
倔强青铜三5 分钟前
苦练Python第23天:元组秘籍与妙用
人工智能·python·面试
Norvyn_729 分钟前
LeetCode|Day18|20. 有效的括号|Python刷题笔记
笔记·python·leetcode
chao_7891 小时前
更灵活方便的初始化、清除方法——fixture【pytest】
服务器·自动化测试·python·pytest
心情好的小球藻1 小时前
Python应用进阶DAY9--类型注解Type Hinting
开发语言·python
都叫我大帅哥1 小时前
LangChain加载HTML内容全攻略:从入门到精通
python·langchain
惜.己1 小时前
使用python读取json数据,简单的处理成元组数组
开发语言·python·测试工具·json
都叫我大帅哥3 小时前
Python的Optional:让你的代码优雅处理“空值”危机
python
曾几何时`5 小时前
基于python和neo4j构建知识图谱医药问答系统
python·知识图谱·neo4j
写写闲篇儿7 小时前
Python+MongoDB高效开发组合
linux·python·mongodb
杭州杭州杭州8 小时前
Python笔记
开发语言·笔记·python