Skip to content

Instantly share code, notes, and snippets.

@skelsec
Created June 1, 2022 20:57
Show Gist options
  • Select an option

  • Save skelsec/da511170a0d39b2c5aa682a17bc4fbaa to your computer and use it in GitHub Desktop.

Select an option

Save skelsec/da511170a0d39b2c5aa682a17bc4fbaa to your computer and use it in GitHub Desktop.
AES-CFB incorrect IV
from Cryptodome.Cipher import AES
from Cryptodome.Random import get_random_bytes
from pypykatz.commons.common import hexdump
data = b"secret"
key = b'\xAA'*16
iv = b'\xAA'*16
cipher = AES.new(key, AES.MODE_CFB, iv=iv)
ct_bytes = cipher.encrypt(data)
print('============ ENCRYPTION ============')
print('DATA:')
print(hexdump(data))
print('IV:')
print(hexdump(iv))
print('KEY')
print(hexdump(key))
print('ENC DATA')
print(hexdump(ct_bytes))
#################################################
dec_iv = b'\xFF'*16
dec_key = b'\xAA'*16
print('============ DECRYPTION ============')
print('ENC DATA')
print(hexdump(ct_bytes))
print('IV:')
print(hexdump(dec_iv))
print('KEY')
print(hexdump(dec_key))
cipher = AES.new(dec_key, AES.MODE_CFB, iv=dec_iv)
data_dec = cipher.decrypt(ct_bytes)
print('DEC DATA')
print(hexdump(data_dec))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment