已知nedpq 在python中使用rsa加密得到公钥私钥
RSA加密的公钥是由两个部分组成,即n和e。私钥是由两个部分组成,即n和d。其中,p和q是用于计算n和d的质数因子。
下面是一个Python程序,可以使用给定的n、e、d、p和q生成RSA公钥和私钥:
from Crypto.PublicKey import RSA
n = 123456789 # replace with your own value
e = 65537
d = 987654321
p = 1234567
q = 987654321
# Calculate the modulus n
modulus = p * q
# Create the public key
public_key = RSA.construct((modulus, e))
# Create the private key
private_key = RSA.construct((modulus, e, d, p, q))
# Export the keys to PEM format
public_key_pem = public_key.export_key()
private_key_pem = private_key.export_key()
# Print the keys
print("Public key: ")
print(public_key_pem.decode("utf-8"))
print("Private key: ")
print(private_key_pem.decode("utf-8"))
请注意,此代码使用了Python的Crypto库来生成RSA密钥对。如果您尚未安装此库,请使用以下命令在命令行中安装它:
pip install pycrypto
``
原文地址: http://www.cveoy.top/t/topic/fEy3 著作权归作者所有。请勿转载和采集!