xpra icon
Bug tracker and wiki

Ticket #933: enctest.py

File enctest.py, 726 bytes (added by Josh, 5 years ago)
Line 
1import binascii
2from Crypto.Cipher import AES
3from pkcs7 import PKCS7Encoder
4
5key = "a891f95cc50bd872e8fcd96cf5030535e273c5210570b3dcfa7946873d167c57".decode('hex')
6iv = "3bbdce68b2736ed96972d56865ad82a2".decode('hex')
7text = "text to encyrptoijaidscashd323eq4"
8
9
10def XpraPadding(data):
11    padding = (32 - len(data) % 32) * " "
12    return data+padding
13
14def PKCS7Padding(data):
15    l = len(data)
16    padding = ""
17    val = 32 - (l % 32)
18    for _ in xrange(val):
19        padding += chr(val)
20    return data + padding
21
22padded = XpraPadding(text)
23a = AES.new(key, AES.MODE_CBC, iv)
24print(a.encrypt(padded).encode('hex'))
25
26pkpadded = PKCS7Padding(text)
27b = AES.new(key, AES.MODE_CBC, iv)
28print(b.encrypt(pkpadded).encode('hex'))