我尝试用pycryptome在Python中实现RSA,加密很好,但是解密函数不,我的代码如下:
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
from Crypto.Signature import pss
from Crypto.Hash import SHA256
class RSA_OBJECT:
def create_KeyPair(self):
self.key = RSA.generate(self.KEY_LENGTH)
def save_PrivateKey(self, file, password):
key_cifrada = self.key.export_key(passphrase=password, pkcs=8,protection="scryptAndAES128-CBC")
file_out = open(file, "wb")
file_out.write(key_cifrada)
file_out.close()
def load_PrivateKey(self, file, password):
key_cifrada = open(file, "rb").read()
self.private_key = RSA.import_key(key_cifrada, passphrase=password)
def save_PublicKey(self, file):
key_pub = self.key.publickey().export_key()
file_out = open(file, "wb")
file_out.write(key_pub)
file_out.close()
def load_PublicKey(self, file):
key_publica = open(file, "rb").read()
self.public_key = RSA.import_key(key_publica)
我不知道为什么,因为我认为代码是正确的,有人能帮我吗?在
你的问题产生了两个不同的键
你应该
^{pr2}$以及
详见here
注意:注意,由于公钥加密,密钥对象具有两个功能。可以将私钥写入文件,将公钥写入另一个文件。这样,就可以分发密钥了。见RSAKey。在
相关问题 更多 >
编程相关推荐