MOD:aes try exception
Showing
1 changed file
with
7 additions
and
1 deletions
| ... | @@ -6,9 +6,15 @@ def aes_encrypt_cbc(data, key, iv): | ... | @@ -6,9 +6,15 @@ def aes_encrypt_cbc(data, key, iv): |
| 6 | return cipher.encrypt(data) | 6 | return cipher.encrypt(data) |
| 7 | 7 | ||
| 8 | def aes_decrypt_cbc(data, key, iv): | 8 | def aes_decrypt_cbc(data, key, iv): |
| 9 | res = '' | ||
| 10 | try: | ||
| 9 | cipher = AES.new(key.encode(), AES.MODE_CBC, iv.encode()) | 11 | cipher = AES.new(key.encode(), AES.MODE_CBC, iv.encode()) |
| 10 | res = cipher.decrypt(b64decode(data)) | 12 | res = cipher.decrypt(b64decode(data)) |
| 11 | return res.decode('utf-8') | 13 | res = res.decode('utf-8') |
| 14 | except Exception as e: | ||
| 15 | res = '' | ||
| 16 | return res | ||
| 17 | |||
| 12 | 18 | ||
| 13 | # 示例使用 | 19 | # 示例使用 |
| 14 | key = 'm0XsOHC52YZ5KtakhpuMSZtF7DhwudmG' # 密钥长度必须是16、24或32字节 | 20 | key = 'm0XsOHC52YZ5KtakhpuMSZtF7DhwudmG' # 密钥长度必须是16、24或32字节 | ... | ... |
-
Please register or sign in to post a comment