]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/env python3 | |
2 | ||
3 | # Allow direct execution | |
4 | import os | |
5 | import sys | |
6 | ||
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
8 | ||
9 | ||
10 | import codecs | |
11 | import subprocess | |
12 | ||
13 | from yt_dlp.aes import aes_encrypt, key_expansion | |
14 | from yt_dlp.utils import intlist_to_bytes | |
15 | ||
16 | secret_msg = b'Secret message goes here' | |
17 | ||
18 | ||
19 | def hex_str(int_list): | |
20 | return codecs.encode(intlist_to_bytes(int_list), 'hex') | |
21 | ||
22 | ||
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 | |
28 | ||
29 | ||
30 | iv = key = [0x20, 0x15] + 14 * [0] | |
31 | ||
32 | r = openssl_encode('aes-128-cbc', key, iv) | |
33 | print('aes_cbc_decrypt') | |
34 | print(repr(r)) | |
35 | ||
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)) | |
41 | ||
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)) |