Created
June 22, 2022 23:43
-
-
Save kangfend/bae30f5cd37df56931837f9390cbb289 to your computer and use it in GitHub Desktop.
Revisions
-
kangfend created this gist
Jun 22, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ from binascii import unhexlify from hkdf import Hkdf import hashlib from base64 import b64decode from Crypto.Cipher import AES from Crypto.Util.Padding import unpad def decrypt(encryption_key, text): encryption_key = unhexlify(encryption_key) key_length = len(encryption_key) kdf = Hkdf(b"\0" * 64, encryption_key, hash=hashlib.sha512) data = b64decode(text[128:]) cipher = AES.new(kdf.expand(b"encryption", key_length), AES.MODE_CBC, data[:AES.block_size]) return unpad(cipher.decrypt(data[key_length:]), AES.block_size)