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