我能够解密运行脚本的消息,但当我使用用户输入法获取加密消息时无法解密。
我有这个简单的脚本:
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import padding
padder = padding.PKCS7(128).padder()
backend = default_backend()
def operation_getmessage():
messagesinput = input("Please, insert messages to decrypt: ")
messagesinput = bytes(messagesinput, "utf-8")
message = padder.update(messagesinput)
message += padder.finalize()
return message
keyinput = input("Please insert the key used for encrypt : ")
print(keyinput)
key = bytes(str(keyinput), 'ascii')
print("key value is :", key)
message = operation_getmessage()
cipher = Cipher(algorithms.TripleDES(key), modes.ECB(), backend=backend)
encryptor = cipher.encryptor()
message_encrypt = encryptor.update(message) + encryptor.finalize()
print("Value of message_encrypted:", message_encrypt)
test = operation_getmessage()
print("Value of test: ", test)
decryptor = cipher.decryptor()
message_decrypt = decryptor.update(test) + decryptor.finalize()
print("Value of message_decrypted is: ", message_decrypt)
unpadder = padding.PKCS7(128).unpadder()
data = unpadder.update(message_decrypt)
print("Value of message is: ", data + unpadder.finalize())
Helenr
肥皂起泡泡
相关分类