logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

generate_aes_testdata.py (1137B)


  1. from __future__ import unicode_literals
  2. import codecs
  3. import subprocess
  4. import os
  5. import sys
  6. sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  7. from youtube_dl.utils import intlist_to_bytes
  8. from youtube_dl.aes import aes_encrypt, key_expansion
  9. secret_msg = b'Secret message goes here'
  10. def hex_str(int_list):
  11. return codecs.encode(intlist_to_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))