Created
June 19, 2018 14:06
-
-
Save ducnhse130201/357f3a12b951c759cf23f6fbe1ce1ce2 to your computer and use it in GitHub Desktop.
demo(Web-Tokenv2).py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import string | |
from base64 import b64decode, b64encode | |
from Crypto.Cipher import AES | |
from hashlib import md5 | |
from Crypto.Hash import HMAC | |
from gzip import * | |
BLOCK_SIZE = 16 | |
pad = lambda s: s + bytearray(((BLOCK_SIZE - len(s) % BLOCK_SIZE) * chr(BLOCK_SIZE - len(s) % BLOCK_SIZE)).encode("utf-8")) | |
#HMAC_SECRET = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(16)) | |
#key = md5(''.join(random.choice(string.ascii_letters + string.digits) for _ in range(32)).encode('utf8')).hexdigest() | |
HMAC_SECRET = 'oKPlvWBXvTebRGiN' | |
key = '536a784f76a4ec72951e3b16f3473d9e' | |
def encrypt(raw): | |
raw = raw + ':user' + HMAC_SECRET | |
raw = compress(raw.encode("utf-8")) | |
print('len_before_pad: ' + str(len(raw))) | |
raw = pad(raw) | |
cipher = AES.new(key) | |
print('len_after_pad: ' + str(len(cipher.encrypt(raw)))) | |
raw = input('Input: ') | |
encrypt(raw) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment