|
8 | 8 | import math |
9 | 9 | from pathlib import Path |
10 | 10 | from os.path import exists |
11 | | -from Crypto import Random |
12 | 11 | from jinja2 import Template |
13 | 12 | from Crypto.Cipher import AES |
| 13 | +from Crypto.Random import get_random_bytes |
| 14 | +from Crypto.Util.Padding import pad |
14 | 15 | from bs4 import BeautifulSoup |
15 | 16 | from mkdocs.plugins import BasePlugin |
16 | 17 | from mkdocs.config import config_options |
|
26 | 27 | ['//cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/core.js','b55ae8027253d4d54c4f1ef3b6254646'], |
27 | 28 | ['//cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/enc-base64.js','f551ce1340a86e5edbfef4a6aefa798f'], |
28 | 29 | ['//cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/cipher-core.js','dfddc0e33faf7a794e0c3c140544490e'], |
29 | | - ['//cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/pad-nopadding.js','e288e14e2cd299c3247120114e1178e6'], |
30 | 30 | ['//cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/md5.js','349498f298a6e6e6a85789d637e89109'], |
31 | 31 | ['//cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/aes.js','da81b91b1b57c279c29b3469649d9b86'], |
32 | 32 | ] |
@@ -124,12 +124,12 @@ def __encrypt_text_aes__(self, text, password): |
124 | 124 | """ Encrypts text with AES-256. """ |
125 | 125 | BLOCK_SIZE = 32 |
126 | 126 | PADDING_CHAR = b'^' |
127 | | - iv = Random.new().read(16) |
| 127 | + iv = get_random_bytes(16) |
128 | 128 | # key must be 32 bytes for AES-256, so the password is hashed with md5 first |
129 | 129 | cipher = AES.new(self.__hash_md5__(password), AES.MODE_CBC, iv) |
130 | 130 | plaintext = text.encode('utf-8') |
131 | 131 | # plaintext must be padded to be a multiple of BLOCK_SIZE |
132 | | - plaintext_padded = plaintext + (BLOCK_SIZE - len(plaintext) % BLOCK_SIZE) * PADDING_CHAR |
| 132 | + plaintext_padded = pad(plaintext, 16, style='pkcs7') |
133 | 133 | ciphertext = cipher.encrypt(plaintext_padded) |
134 | 134 | return ( |
135 | 135 | base64.b64encode(iv), |
|
0 commit comments