]> jfr.im git - yt-dlp.git/blame - devscripts/generate_aes_testdata.py
[test] Add tests for aes
[yt-dlp.git] / devscripts / generate_aes_testdata.py
CommitLineData
a7d9ded4
JMF
1from __future__ import unicode_literals
2
3import codecs
4import subprocess
5
6import os
7import sys
8sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
9
10from youtube_dl.utils import intlist_to_bytes
11from youtube_dl.aes import aes_encrypt, key_expansion
12
13secret_msg = b'Secret message goes here'
14
15
16def hex_str(int_list):
17 return codecs.encode(intlist_to_bytes(int_list), 'hex')
18
19
20def openssl_encode(algo, key, iv):
21 cmd = ['openssl', 'enc', '-e', '-' + algo, '-K', hex_str(key), '-iv', hex_str(iv)]
22 prog = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
23 out, _ = prog.communicate(secret_msg)
24 return out
25
26iv = key = [0x20, 0x15] + 14 * [0]
27
28r = openssl_encode('aes-128-cbc', key, iv)
29print('aes_cbc_decrypt')
30print(repr(r))
31
32password = key
33new_key = aes_encrypt(password, key_expansion(password))
34r = openssl_encode('aes-128-ctr', new_key, iv)
35print('aes_decrypt_text')
36print(repr(r))