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
相关推荐
多米Domi0114 分钟前
0x3f 第21天 三更java进阶1-35 hot100普通数组
java·python·算法·leetcode·动态规划
小程故事多_8016 分钟前
从零吃透PyTorch,最易懂的入门全指南
人工智能·pytorch·python
Keep_Trying_Go1 小时前
基于无监督backbone无需训练的类别无关目标统计CountingDINO算法详解
人工智能·python·算法·多模态·目标统计
weixin_433179332 小时前
python - for循环,字符串,元组基础
开发语言·python
^哪来的&永远~2 小时前
Python 轻量级 UI:EEG 与 fNIRS 预处理图形界面
python·可视化·功能连接·eeg·mne·fnirs·eeglab
AI大佬的小弟2 小时前
Python基础(11):Python中函数参数的进阶模式详解
python·lambda函数·函数的参数解释·函数的参数进阶·位置参数·关键词参数·匿名函数与普通函数
智算菩萨2 小时前
Python可以做哪些小游戏——基于Python 3.13最新特性的游戏开发全指南(15万字超长文章,强烈建议收藏阅读)
python·pygame
智航GIS2 小时前
9.1 多线程入门
java·开发语言·python
nvd112 小时前
FastMCP 开发指南: 5分钟入门
人工智能·python
weixin_433179333 小时前
Python - word jumble游戏
开发语言·python