这是我的代码:
# -*- coding: utf-8 -*-
from Crypto.PublicKey import RSA
from Crypto.Cipher import AES, PKCS1_OAEP
import ast
file_in = open("secret.bin", "rb")
private_key = RSA.import_key(open("private.pem").read())
enc_session_key, nonce, tag, ciphertext = \
[ file_in.read(x) for x in (private_key.size_in_bytes(), 16, 16, -1) ]
# Decrypt the session key with the private RSA key
cipher_rsa = PKCS1_OAEP.new(private_key)
session_key = cipher_rsa.decrypt(enc_session_key)
# Decrypt the data with the AES session key
cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
data = cipher_aes.decrypt_and_verify(ciphertext, tag)
t=data.decode("ascii",'ignore')
t= ast.literal_eval(t)
print (t)
for items in t:
print(items," = ",t[items])
在我的PC上,它可以正常工作,并且每当我解密时,它都会返回相同的文本。 但是在我的服务器上,每次的结果都是不同的。某些零件丢失或放置在错误的位置。软件包都已更新并安装。