Python分离RSA公钥的n和e参数

直接打开公钥文件通过RSA.importKey(key).nRSA.importKey(key).e进行处理:

1
2
3
4
5
6
7
8
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_OAEP
import gmpy2
import base64
import rsa
pub = open(r"~/key.pub",'r').read()
n = RSA.importKey(pub).n
e = RSA.importKey(pub).e