]>
jfr.im git - yt-dlp.git/blob - devscripts/generate_aes_testdata.py
2 from __future__
import unicode_literals
9 sys
.path
.insert(0, os
.path
.dirname(os
.path
.dirname(os
.path
.abspath(__file__
))))
11 from yt_dlp
.utils
import intlist_to_bytes
12 from yt_dlp
.aes
import aes_encrypt
, key_expansion
14 secret_msg
= b
'Secret message goes here'
17 def hex_str(int_list
):
18 return codecs
.encode(intlist_to_bytes(int_list
), 'hex')
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
)
28 iv
= key
= [0x20, 0x15] + 14 * [0]
30 r
= openssl_encode('aes-128-cbc', key
, iv
)
31 print('aes_cbc_decrypt')
35 new_key
= aes_encrypt(password
, key_expansion(password
))
36 r
= openssl_encode('aes-128-ctr', new_key
, iv
)
37 print('aes_decrypt_text 16')
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')