Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64
- import json
- from typing import Tuple
- from Cryptodome.Cipher import AES
- from Cryptodome.Random.random import sample
- def encrypt(text: str, encoding='utf-8') -> Tuple[str, str]:
- """
- Credit to https://www.jianshu.com/p/87309e36e027
- and https://segmentfault.com/a/1190000012818254?utm_source=tuicool&utm_medium=referral
- """
- random_string = ''.join(sample([c for c in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'], 16))
- pubkey = '010001'
- modulus = '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee3' \
- '41f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d' \
- '3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
- rs = int(random_string[::-1].encode(encoding).hex(), 16) ** int(pubkey, 16) % int(modulus, 16)
- seckey = format(rs, 'x').zfill(256)
- for random_string in [
- '0CoJUm6Qyw8W8jud',
- random_string
- ]:
- encryptor = AES.new(random_string.encode(encoding), AES.MODE_CBC, iv='0102030405060708'.encode(encoding))
- pad = 16 - len(text) % 16
- text = (text + pad * chr(pad)).encode(encoding)
- text = base64.b64encode(encryptor.encrypt(text)).decode(encoding)
- return text, seckey
- if __name__ == '__main__':
- # out = encrypt(json.dumps({
- # '/api/nuser/account/get': {},
- # '/api/music-vip-membership/front/vip/info': {},
- # '/api/purchased/redvip/vipstatus': {},
- # }))
- out = encrypt(json.dumps({
- 's': 'One',
- 'type': 1,
- 'limit': 30,
- 'offset': 0
- }))
- body = 'params=' + out[0].replace('/', '%2F').replace('+', '%2B').replace('=', '%3D') + \
- '&encSecKey=' + out[1]
- print(body)
Add Comment
Please, Sign In to add comment