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.
Decrypt Codeigniter Encryption
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)
@kangfend
Copy link
Author

Requirements:

pip install pycryptodome hkdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment