]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
54007a45 | 2 | |
3 | # Allow direct execution | |
a7d9ded4 JMF |
4 | import os |
5 | import sys | |
f8271158 | 6 | |
a7d9ded4 JMF |
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
8 | ||
54007a45 | 9 | |
10 | import codecs | |
11 | import subprocess | |
12 | ||
7a5c1cfe | 13 | from yt_dlp.aes import aes_encrypt, key_expansion |
f8271158 | 14 | from yt_dlp.utils import intlist_to_bytes |
a7d9ded4 JMF |
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 | ||
582be358 | 29 | |
a7d9ded4 JMF |
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) | |
f9544f6e JMF |
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') | |
a7d9ded4 | 46 | print(repr(r)) |