Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit aba2e8f

Browse files
committed
Swap out pycrypto (unmaintained) for cryptography
1 parent 9175f0a commit aba2e8f

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

pysnap/utils.py

+14-7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
from uuid import uuid4
1111

1212
import requests
13-
from Crypto.Cipher import AES
1413

1514
URL = 'https://feelinsonice-hrd.appspot.com/bq/'
15+
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
16+
from cryptography.hazmat.backends import default_backend
1617

1718
SECRET = b'iEk21fuwZApXlz93750dmW22pw389dPwOk'
1819
STATIC_TOKEN = 'm198sOkJEn37DjqZ32lpRu76xmw288xSQ9'
@@ -38,18 +39,24 @@ def pkcs5_pad(data, blocksize=16):
3839

3940

4041
def decrypt(data):
41-
cipher = AES.new(BLOB_ENCRYPTION_KEY, AES.MODE_ECB)
42-
return cipher.decrypt(pkcs5_pad(data))
42+
cipher = Cipher(algorithms.AES(BLOB_ENCRYPTION_KEY), modes.ECB(),
43+
backend=default_backend())
44+
decryptor = cipher.decryptor()
45+
return decryptor.update(pkcs5_pad(data)) + decryptor.finalize()
4346

4447

4548
def decrypt_story(data, key, iv):
46-
cipher = AES.new(key, AES.MODE_CBC, iv)
47-
return cipher.decrypt(pkcs5_pad(data))
49+
cipher = Cipher(algorithms.AES(key), modes.CBC(iv),
50+
backend=default_backend())
51+
decryptor = cipher.decryptor()
52+
return decryptor.update(pkcs5_pad(data)) + decryptor.finalize()
4853

4954

5055
def encrypt(data):
51-
cipher = AES.new(BLOB_ENCRYPTION_KEY, AES.MODE_ECB)
52-
return cipher.encrypt(pkcs5_pad(data))
56+
cipher = Cipher(algorithms.AES(BLOB_ENCRYPTION_KEY), modes.ECB(),
57+
backend=default_backend())
58+
encryptor = cipher.encryptor()
59+
return encryptor.update(pkcs5_pad(data)) + encryptor.finalize()
5360

5461

5562
def timestamp():

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
docopt==0.6.1
2-
pycrypto==2.6.1
32
requests==2.2.1
3+
cryptography==1.2.2

0 commit comments

Comments
 (0)