Google AppEngine目前使用old version of PyCrypto。
制作RSAkey后,我找不到任何导出公钥的方法。
目前pycrypto 2.01的文档为404.我在当前代码中看到的.export方法在PyCrypto 2.01上不起作用:
制作密钥对:
rsa_key = RSA.generate(384, random_generator)
检查可用方法:
In [84]: rsa_key.publickey. <tab>
RSAkey.publickey.__call__ RSAkey.publickey.__func__ RSAkey.publickey.__reduce__ RSAkey.publickey.__str__
RSAkey.publickey.__class__ RSAkey.publickey.__get__ RSAkey.publickey.__reduce_ex__ RSAkey.publickey.__subclasshook__
RSAkey.publickey.__cmp__ RSAkey.publickey.__getattribute__ RSAkey.publickey.__repr__ RSAkey.publickey.im_class
RSAkey.publickey.__delattr__ RSAkey.publickey.__hash__ RSAkey.publickey.__self__ RSAkey.publickey.im_func
RSAkey.publickey.__doc__ RSAkey.publickey.__init__ RSAkey.publickey.__setattr__ RSAkey.publickey.im_self
RSAkey.publickey.__format__ RSAkey.publickey.__new__ RSAkey.publickey.__sizeof__
打印不起作用。
答案 0 :(得分:1)
应该可以使用pickle
模块,前提是互操作性对您来说并不重要。
import pickle
keyout = pickle.dumps(rsa_key)
# Save keyout into a file or a db
[ ... ]
# Retrieve keyin from the same file or db
rsa_key = pickle.loads(keyin)
答案 1 :(得分:1)
只需查看代码即可:
def generate(bits, randfunc, progress_func=None):
"""generate(bits:int, randfunc:callable, progress_func:callable)
Generate an RSA key of length 'bits', using 'randfunc' to get
random data and 'progress_func', if present, to display
the progress of the key generation.
"""
obj=RSAobj()
# Generate random number from 0 to 7
difference=ord(randfunc(1)) & 7
# Generate the prime factors of n
if progress_func: progress_func('p\n')
obj.p=pubkey.getPrime(bits/2, randfunc)
if progress_func: progress_func('q\n')
obj.q=pubkey.getPrime((bits/2)+difference, randfunc)
obj.n=obj.p*obj.q
# Generate encryption exponent
if progress_func: progress_func('e\n')
obj.e=pubkey.getPrime(17, randfunc)
if progress_func: progress_func('d\n')
obj.d=pubkey.inverse(obj.e, (obj.p-1)*(obj.q-1))
return obj
This site可以很好地解释每个变量的含义。