-
Notifications
You must be signed in to change notification settings - Fork 9
/
sign.py
46 lines (34 loc) · 1.43 KB
/
sign.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# webtoons sign reversed
from rsa import PublicKey, encrypt as rsae
from binascii import hexlify
from urllib.parse import quote
from hmac import new
from hashlib import sha1
from time import time, time
from base64 import b64encode
class Sign:
def __init__(self) -> None:
self.sign_key = b"gUtPzJFZch4ZyAGviiyH94P99lQ3pFdRTwpJWDlSGFfwgpr6ses5ALOxWHOIT7R1"
def get_message(self, string, stamp):
string = string[:min(255, len(string))]
return string + stamp
def sign(self, uri):
mac = new(self.sign_key, digestmod=sha1)
stamp = str(int(time() * 1000))
mac.update(self.get_message(uri, stamp).encode('utf-8'))
md = quote(b64encode(mac.digest()))
builder = []
builder.append(uri)
builder.append('&') if '?' in uri else builder.append('?')
builder.append("msgpad=" + stamp)
builder.append("&md=" + md)
return ''.join(builder)
def chrlen(self, n: str) -> str:
return chr(len(n))
def encrypt(self, json, mail, pw):
string = f"{self.chrlen(json['sessionKey'])}{json['sessionKey']}{self.chrlen(mail)}{mail}{self.chrlen(pw)}{pw}".encode()
mod = int(json['nvalue'], 16)
evl = int(json['evalue'], 16)
pbk = PublicKey(evl, mod)
out = rsae(string, pbk)
return hexlify(out).decode('utf-8')