pythonrsa加密与sha256加密

[复制链接]
发表于 2025-10-29 14:05:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
这个比力故意思,不外我前端不太熟悉,js也是二懂二懂的。
登录校验

近来的业务涉及到这一块,这边分析前端的源代码、发现涉及两种登录方式。
起首在这边找前端源代码
sha256
  1. xxxx: function() {
  2.      var t = a("6c27").sha256;
  3.      l["a"].post("login/xxxx", {
  4.          userCode: this.loginForm.usercode
  5.      }).then((function(a) {
  6.          var i = a.data;
  7.          i && i.data && !i.data.firstLoginFlag && i.data.hash && i.data.ts ? (e.shaStr = t(i.data.hash + i.data.ts),
  8.          e.sildeSuccessCallBack(!1)) : e.isShow = !0
  9.      }
  10.      )).catch((function(t) {
  11.          e.loginText = "登 录",
  12.          e.loading = !1,
  13.          e.$message({
  14.              message: "网络错误,请刷新重试",
  15.              type: "warning"
  16.          }),
  17.          console.log(t)
  18.      }
  19.      ))
  20. },
复制代码
起首分析后端接口,再从前端源代码中搜刮对应的urllogin/xxxx,这里是通过链接获取会话id,与时间timestamp,相加,加了后举行sha256加密。t(i.data.hash + i.data.ts)
  1. import hashlib
  2. def sha256_hash(text):
  3.     if not isinstance(text, bytes):
  4.         text=text.encode('utf-8')
  5.     hash_object = hashlib.sha256()
  6.     hash_object.update(text)
  7.     hex_dig = hash_object.hexdigest()
  8.     return hex_dig
复制代码
RSA加密
  1. Object(l["a"])({
  2.     method: "post",
  3.     url: "/login/xxxx"
  4. }).then((function(s) {
  5.     if (0 === s.data.status) {
  6.         var p = o.a.KEYUTIL.getKey(s.data.data)
  7.           , m = o.a.KJUR.crypto.Cipher.encrypt(u, p)
  8.           , v = o.a.hextob64(m)
  9.         };
  10. }
复制代码
rsa的一个特点是每次加密效果都不一样,由于有随机的padding,这里可以看到加密是先获取公钥,再加密,末了转为base64。
  1. from Crypto.PublicKey import RSA
  2. from Crypto.Cipher import PKCS1_v1_5 as Cipher_pksc1_v1_5
  3. import base64
  4. def encrpt(password, public_key):
  5.     rsakey = RSA.importKey(public_key)
  6.     cipher = Cipher_pksc1_v1_5.new(rsakey)
  7.     cipher_text = base64.b64encode(cipher.encrypt(password.encode())).decode()
  8.     # cipher_text = sha256_hash(cipher.encrypt(password.encode()))
  9.     return cipher_text
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表