yt-dlp/devscripts/generate_aes_testdata.py

46 lines
1.1 KiB
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
# Allow direct execution
2015-03-21 11:07:23 +00:00
import os
import sys
2015-03-21 11:07:23 +00:00
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import codecs
import subprocess
from yt_dlp.aes import aes_encrypt, key_expansion
2015-03-21 11:07:23 +00:00
secret_msg = b'Secret message goes here'
def hex_str(int_list):
return codecs.encode(bytes(int_list), 'hex')
2015-03-21 11:07:23 +00:00
def openssl_encode(algo, key, iv):
cmd = ['openssl', 'enc', '-e', '-' + algo, '-K', hex_str(key), '-iv', hex_str(iv)]
prog = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out, _ = prog.communicate(secret_msg)
return out
2015-03-21 11:07:23 +00:00
iv = key = [0x20, 0x15] + 14 * [0]
r = openssl_encode('aes-128-cbc', key, iv)
print('aes_cbc_decrypt')
print(repr(r))
password = key
new_key = aes_encrypt(password, key_expansion(password))
r = openssl_encode('aes-128-ctr', new_key, iv)
print('aes_decrypt_text 16')
print(repr(r))
password = key + 16 * [0]
new_key = aes_encrypt(password, key_expansion(password)) * (32 // 16)
r = openssl_encode('aes-256-ctr', new_key, iv)
print('aes_decrypt_text 32')
2015-03-21 11:07:23 +00:00
print(repr(r))