要解决"AES解密失败"的问题,你可以尝试以下步骤:
from Crypto.Cipher import AES
import base64
def aes_decrypt(ciphertext, key):
cipher = AES.new(key.encode(), AES.MODE_ECB)
decrypted = cipher.decrypt(base64.b64decode(ciphertext))
return decrypted.decode()
ciphertext = "..."
key = "..."
plaintext = aes_decrypt(ciphertext, key)
print(plaintext)
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
import base64
def aes_decrypt(ciphertext, key):
cipher = AES.new(key.encode(), AES.MODE_ECB)
decrypted = cipher.decrypt(base64.b64decode(ciphertext))
return decrypted.decode()
ciphertext = "..."
key = "mykey"
key = key.ljust(32, '\0') # 将密钥填充到32字节长度
plaintext = aes_decrypt(ciphertext, key)
print(plaintext)
from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import base64
def aes_decrypt(ciphertext, key):
cipher = AES.new(key.encode(), AES.MODE_CBC, iv=iv.encode())
decrypted = cipher.decrypt(base64.b64decode(ciphertext))
unpadded = unpad(decrypted, AES.block_size)
return unpadded.decode()
ciphertext = "..."
key = "..."
iv = "..."
plaintext = aes_decrypt(ciphertext, key)
print(plaintext)
from Crypto.Cipher import AES
import base64
def aes_decrypt(ciphertext, key):
cipher = AES.new(key.encode(), AES.MODE_ECB)
decrypted = cipher.decrypt(base64.b64decode(ciphertext))
return decrypted.decode()
ciphertext = "..."
key = "..."
plaintext = aes_decrypt(ciphertext, key)
print(plaintext)
通过检查以上步骤,你应该能够解决"AES解密失败"的问题。如果问题仍然存在,你可以检查密文是否被正确传递和读取,或者尝试使用其他调试方法来定位问题的具体原因。
上一篇:AES解密后不能得到原始值