|
1 | 1 | from chef.exceptions import ChefUnsupportedEncryptionVersionError, ChefDecryptionError |
2 | | -from M2Crypto.EVP import Cipher |
| 2 | +from chef.aes import AES256Cipher |
3 | 3 |
|
4 | 4 | import os |
5 | 5 | import hmac |
@@ -52,14 +52,13 @@ def __init__(self, key, data): |
52 | 52 | self.key = hashlib.sha256(key).digest() |
53 | 53 | self.data = data |
54 | 54 | self.iv = os.urandom(8).encode('hex') |
55 | | - self.encryptor = Cipher(alg=EncryptedDataBagItem.AES_MODE, key=self.key, iv=self.iv, op=1) |
| 55 | + self.encryptor = AES256Cipher(key=self.key, iv=self.iv) |
56 | 56 | self.encrypted_data = None |
57 | 57 |
|
58 | 58 | def encrypt(self): |
59 | 59 | if self.encrypted_data is None: |
60 | 60 | data = json.dumps({'json_wrapper': self.data}) |
61 | | - update_data = self.encryptor.update(data) |
62 | | - self.encrypted_data = update_data + self.encryptor.final() |
| 61 | + self.encrypted_data = self.encryptor.encrypt(data) |
63 | 62 | del self.encryptor |
64 | 63 | return self.encrypted_data |
65 | 64 |
|
@@ -108,10 +107,10 @@ def __init__(self, key, data, iv): |
108 | 107 | self.key = hashlib.sha256(key).digest() |
109 | 108 | self.data = base64.standard_b64decode(data) |
110 | 109 | self.iv = base64.standard_b64decode(iv) |
111 | | - self.decryptor = Cipher(alg=EncryptedDataBagItem.AES_MODE, key=self.key, iv=self.iv, op=0) |
| 110 | + self.decryptor = AES256Cipher(key=self.key, iv=self.iv) |
112 | 111 |
|
113 | 112 | def decrypt(self): |
114 | | - value = self.decryptor.update(self.data) + self.decryptor.final() |
| 113 | + value = self.decryptor.decrypt(self.data) |
115 | 114 | del self.decryptor |
116 | 115 | # Strip all the whitespace and sequence control characters |
117 | 116 | value = value.strip(reduce(lambda x,y: "%s%s" % (x,y), EncryptedDataBagItem.Decryptors.STRIP_CHARS)) |
|
0 commit comments