Release 2024.11.18
[yt-dlp3.git] / devscripts / generate_aes_testdata.py
blob73cf803b8f6d140670a7a2029da9264e090a161e
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
15 secret_msg = b'Secret message goes here'
18 def hex_str(int_list):
19 return codecs.encode(bytes(int_list), 'hex')
22 def openssl_encode(algo, key, iv):
23 cmd = ['openssl', 'enc', '-e', '-' + algo, '-K', hex_str(key), '-iv', hex_str(iv)]
24 prog = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
25 out, _ = prog.communicate(secret_msg)
26 return out
29 iv = key = [0x20, 0x15] + 14 * [0]
31 r = openssl_encode('aes-128-cbc', key, iv)
32 print('aes_cbc_decrypt')
33 print(repr(r))
35 password = key
36 new_key = aes_encrypt(password, key_expansion(password))
37 r = openssl_encode('aes-128-ctr', new_key, iv)
38 print('aes_decrypt_text 16')
39 print(repr(r))
41 password = key + 16 * [0]
42 new_key = aes_encrypt(password, key_expansion(password)) * (32 // 16)
43 r = openssl_encode('aes-256-ctr', new_key, iv)
44 print('aes_decrypt_text 32')
45 print(repr(r))