fix: 修复默认 gcm key padding

pull/8797/head
ibuler 2022-08-22 14:13:26 +08:00 committed by Jiangjie.Bai
parent 5f1b7ff8f9
commit 60cb1f8136
1 changed files with 10 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import re
from Cryptodome.Cipher import AES, PKCS1_v1_5
from Cryptodome.Random import get_random_bytes
from Cryptodome.PublicKey import RSA
from Cryptodome.Util.Padding import pad
from Cryptodome import Random
from gmssl.sm4 import CryptSM4, SM4_ENCRYPT, SM4_DECRYPT
@ -107,7 +108,15 @@ class AESCryptoGCM:
"""
def __init__(self, key):
self.key = padding_key(key)
self.key = self.process_key(key)
@staticmethod
def process_key(key):
if not isinstance(key, bytes):
key = bytes(key, encoding='utf-8')
if len(key) >= 32:
return key[:32]
return pad(key, 32)
def encrypt(self, text):
"""