| Total Complexity | 3 |
| Total Lines | 17 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| 1 | # -*- coding: utf-8 -*- |
||
| 7 | 6 | class WeChatCipher(object): |
|
| 8 | |||
| 9 | 6 | def __init__(self, key): |
|
| 10 | 6 | backend = default_backend() |
|
| 11 | 6 | self.cipher = Cipher( |
|
| 12 | algorithms.AES(key), |
||
| 13 | modes.CBC(key[:16]), |
||
| 14 | backend=backend |
||
| 15 | ) |
||
| 16 | |||
| 17 | 6 | def encrypt(self, plaintext): |
|
| 18 | 6 | encryptor = self.cipher.encryptor() |
|
| 19 | 6 | return encryptor.update(plaintext) + encryptor.finalize() |
|
| 20 | |||
| 21 | 6 | def decrypt(self, ciphertext): |
|
| 22 | 6 | decryptor = self.cipher.decryptor() |
|
| 23 | return decryptor.update(ciphertext) + decryptor.finalize() |
||
| 24 |