]>
Commit | Line | Data |
---|---|---|
cc52de43 | 1 | #!/usr/bin/env python3 |
a7d9ded4 | 2 | import codecs |
a7d9ded4 | 3 | import os |
f8271158 | 4 | import subprocess |
a7d9ded4 | 5 | import sys |
f8271158 | 6 | |
a7d9ded4 JMF |
7 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
8 | ||
7a5c1cfe | 9 | from yt_dlp.aes import aes_encrypt, key_expansion |
f8271158 | 10 | from yt_dlp.utils import intlist_to_bytes |
a7d9ded4 JMF |
11 | |
12 | secret_msg = b'Secret message goes here' | |
13 | ||
14 | ||
15 | def hex_str(int_list): | |
16 | return codecs.encode(intlist_to_bytes(int_list), 'hex') | |
17 | ||
18 | ||
19 | def openssl_encode(algo, key, iv): | |
20 | cmd = ['openssl', 'enc', '-e', '-' + algo, '-K', hex_str(key), '-iv', hex_str(iv)] | |
21 | prog = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
22 | out, _ = prog.communicate(secret_msg) | |
23 | return out | |
24 | ||
582be358 | 25 | |
a7d9ded4 JMF |
26 | iv = key = [0x20, 0x15] + 14 * [0] |
27 | ||
28 | r = openssl_encode('aes-128-cbc', key, iv) | |
29 | print('aes_cbc_decrypt') | |
30 | print(repr(r)) | |
31 | ||
32 | password = key | |
33 | new_key = aes_encrypt(password, key_expansion(password)) | |
34 | r = openssl_encode('aes-128-ctr', new_key, iv) | |
f9544f6e JMF |
35 | print('aes_decrypt_text 16') |
36 | print(repr(r)) | |
37 | ||
38 | password = key + 16 * [0] | |
39 | new_key = aes_encrypt(password, key_expansion(password)) * (32 // 16) | |
40 | r = openssl_encode('aes-256-ctr', new_key, iv) | |
41 | print('aes_decrypt_text 32') | |
a7d9ded4 | 42 | print(repr(r)) |