Skip to content

Instantly share code, notes, and snippets.

@Dewep
Last active March 30, 2017 19:56
Show Gist options
  • Save Dewep/8793d7c857e629d14943 to your computer and use it in GitHub Desktop.
Save Dewep/8793d7c857e629d14943 to your computer and use it in GitHub Desktop.
aes-128-cbc
root@toto:~# echo -n 0000000000000000 | xxd -g 0
0000000: 30303030303030303030303030303030 0000000000000000
root@toto:~# echo -n 1234567890 | openssl aes-128-cbc -e -K 30303030303030303030303030303030 -iv 00000000000000000000000000000000 | md5sum
aa8301604be724a92e1f223e14caea68 -
root@toto:~# python2 -c 'import sys, Crypto.Cipher.AES as A; sys.stdout.write(A.new("0"*16, A.MODE_CBC, "\0"*16).encrypt("1234567890\6\6\6\6\6\6"))' | md5sum
aa8301604be724a92e1f223e14caea68 -
from Crypto import Random
from Crypto.Cipher import AES
key = "0" * 16
keyHex = key.encode('hex')
keyHex = '\0' * 16
with open("in", "rb") as chunk:
chunk_data = chunk.read()
pad = 16 - (len(chunk_data) % 16)
chunk_data += chr(pad) * pad
aes = AES.new(key, AES.MODE_CBC, keyHex)
chunk_data = aes.encrypt(chunk_data)
with open("out2.ts", "wb") as chunk:
chunk.write(chunk_data)
# echo toto > in
# openssl aes-128-cbc -e -in in -out out.ts -iv 0000000000000000 -K 30303030303030303030303030303030
# diff out*
@Dewep
Copy link
Author

Dewep commented Jul 8, 2015

En fonction du vi_counter :
("%032X" % vi_counter).decode("hex")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment