]>
Commit | Line | Data |
---|---|---|
a7d9ded4 JMF |
1 | from __future__ import unicode_literals |
2 | ||
3 | import codecs | |
4 | import subprocess | |
5 | ||
6 | import os | |
7 | import sys | |
8 | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
9 | ||
cefecac1 U |
10 | from youtube_dlc.utils import intlist_to_bytes |
11 | from youtube_dlc.aes import aes_encrypt, key_expansion | |
a7d9ded4 JMF |
12 | |
13 | secret_msg = b'Secret message goes here' | |
14 | ||
15 | ||
16 | def hex_str(int_list): | |
17 | return codecs.encode(intlist_to_bytes(int_list), 'hex') | |
18 | ||
19 | ||
20 | def 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 | ||
582be358 | 26 | |
a7d9ded4 JMF |
27 | iv = key = [0x20, 0x15] + 14 * [0] |
28 | ||
29 | r = openssl_encode('aes-128-cbc', key, iv) | |
30 | print('aes_cbc_decrypt') | |
31 | print(repr(r)) | |
32 | ||
33 | password = key | |
34 | new_key = aes_encrypt(password, key_expansion(password)) | |
35 | r = openssl_encode('aes-128-ctr', new_key, iv) | |
f9544f6e JMF |
36 | print('aes_decrypt_text 16') |
37 | print(repr(r)) | |
38 | ||
39 | password = key + 16 * [0] | |
40 | new_key = aes_encrypt(password, key_expansion(password)) * (32 // 16) | |
41 | r = openssl_encode('aes-256-ctr', new_key, iv) | |
42 | print('aes_decrypt_text 32') | |
a7d9ded4 | 43 | print(repr(r)) |