generate_aes_testdata.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. # Allow direct execution
  3. import os
  4. import sys
  5. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  6. import codecs
  7. import subprocess
  8. from yt_dlp.aes import aes_encrypt, key_expansion
  9. secret_msg = b'Secret message goes here'
  10. def hex_str(int_list):
  11. return codecs.encode(bytes(int_list), 'hex')
  12. def openssl_encode(algo, key, iv):
  13. cmd = ['openssl', 'enc', '-e', '-' + algo, '-K', hex_str(key), '-iv', hex_str(iv)]
  14. prog = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  15. out, _ = prog.communicate(secret_msg)
  16. return out
  17. iv = key = [0x20, 0x15] + 14 * [0]
  18. r = openssl_encode('aes-128-cbc', key, iv)
  19. print('aes_cbc_decrypt')
  20. print(repr(r))
  21. password = key
  22. new_key = aes_encrypt(password, key_expansion(password))
  23. r = openssl_encode('aes-128-ctr', new_key, iv)
  24. print('aes_decrypt_text 16')
  25. print(repr(r))
  26. password = key + 16 * [0]
  27. new_key = aes_encrypt(password, key_expansion(password)) * (32 // 16)
  28. r = openssl_encode('aes-256-ctr', new_key, iv)
  29. print('aes_decrypt_text 32')
  30. print(repr(r))