马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
这个比力故意思,不外我前端不太熟悉,js也是二懂二懂的。
登录校验
近来的业务涉及到这一块,这边分析前端的源代码、发现涉及两种登录方式。
起首在这边找前端源代码
sha256
- 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)- 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加密
- 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。- 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
复制代码 |