正在关注this post我正在创建一个小型Python脚本,可以输入公共RSA密钥并输出私有RSA密钥。Argparse:如果提供另一个参数,则绕过参数
现在它通过传递的参数是这样的:
./Converter.py -input publikey.pem
这是代码:
<!-- language: lang-py -->
parser = argparse.ArgumentParser()
parser.add_argument('-i', dest='infile', help="input a .pem file which contains pubilc key")
args = parser.parse_args()
# --- Here we search for n and e ---
PublicKey = args.infile
OpenPublicKey = open(PublicKey, 'r')
ReadPublicKey = OpenPublicKey.read()
TheKey = RSA.importKey(ReadPublicKey)
n = long(TheKey.n)
e = long(TheKey.e)
print 'This is modulus n: ', n, '\n'
print 'This is public exponent e: ', e, '\n'
我也想剧本的时候没有公钥.pem
文件工作,在这种情况下用户需要输入n
和e
这样:
./Converter.py -n 7919 -e 65537
我使用的是,现在基本上Python正在从.pem
文件中提取n
和e
。
但我想绕过这种提取时由用户提供n
和e
为了找到一个给定的公钥私钥,你将不得不因素模'ñ '。请记住,模数'n'应大于'e'(实际上是λ(n)> e') –