[ie] Resolve `language` to ISO639-2 for ISM formats (#11359)
[yt-dlp3.git] / devscripts / generate_aes_testdata.py
blob7f3c88bcfbb7704be3f08e05977f93a9604a19cf
1 #!/usr/bin/env python3
3 # Allow direct execution
4 import os
5 import sys
7 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
10 import codecs
11 import subprocess
13 from yt_dlp.aes import aes_encrypt, key_expansion
14 from yt_dlp.utils import intlist_to_bytes
16 secret_msg = b'Secret message goes here'
19 def hex_str(int_list):
20 return codecs.encode(intlist_to_bytes(int_list), 'hex')
23 def openssl_encode(algo, key, iv):
24 cmd = ['openssl', 'enc', '-e', '-' + algo, '-K', hex_str(key), '-iv', hex_str(iv)]
25 prog = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
26 out, _ = prog.communicate(secret_msg)
27 return out
30 iv = key = [0x20, 0x15] + 14 * [0]
32 r = openssl_encode('aes-128-cbc', key, iv)
33 print('aes_cbc_decrypt')
34 print(repr(r))
36 password = key
37 new_key = aes_encrypt(password, key_expansion(password))
38 r = openssl_encode('aes-128-ctr', new_key, iv)
39 print('aes_decrypt_text 16')
40 print(repr(r))
42 password = key + 16 * [0]
43 new_key = aes_encrypt(password, key_expansion(password)) * (32 // 16)
44 r = openssl_encode('aes-256-ctr', new_key, iv)
45 print('aes_decrypt_text 32')
46 print(repr(r))