Skip to content

Instantly share code, notes, and snippets.

@kangfend
Created June 22, 2022 23:43
Show Gist options
  • Save kangfend/bae30f5cd37df56931837f9390cbb289 to your computer and use it in GitHub Desktop.
Save kangfend/bae30f5cd37df56931837f9390cbb289 to your computer and use it in GitHub Desktop.

Revisions

  1. kangfend created this gist Jun 22, 2022.
    17 changes: 17 additions & 0 deletions decrypt.py
    Original 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)