我希望能够在python中单独从密码(和盐)生成和重新生成相同的RSA密钥.
目前我使用pycrypto进行此操作,但是,它似乎没有单独从密码生成相同的确切密钥.原因似乎是当pycrypto生成RSA密钥时,它在内部使用某种随机数.
目前我的代码如下:
import DarkCloudCryptoLib as dcCryptoLib #some costume library for crypto from Crypto.PublicKey import RSA password = "password" new_key1 = RSA.generate(1024) #rsaObj exportedKey1 = new_key1.exportKey('DER', password, pkcs=1) key1 = RSA.importKey(exportedKey1) new_key2 = RSA.generate(1024) #rsaObj exportedKey2 = new_key2.exportKey('DER', password, pkcs=1) key2 = RSA.importKey(exportedKey2) print dcCryptoLib.equalRSAKeys(key1, key2) #wish to return True but it doesn't
我真的不在乎我是否必须不使用pycrypto,只要我可以单独从密码和盐生成这些RSA密钥.
我在这里先向您的帮助表示感谢.
仅供参考,这是dcCryptoLib.equalRSAKeys(key1,key2)函数的样子:
def equalRSAKeys(rsaKey1, rsaKey2): public_key = rsaKey1.publickey().exportKey("DER") private_key = rsaKey1.exportKey("DER") pub_new_key = rsaKey2.publickey().exportKey("DER") pri_new_key = rsaKey2.exportKey("DER") boolprivate = (private_key == pri_new_key) boolpublic = (public_key == pub_new_key) return (boolprivate and boolpublic)
注意:另外,我只使用RSA进行身份验证.因此,任何提供生成安全非对称签名/验证密码生成方法的解决方案都是我的应用程序可接受的解决方案.虽然,从我感觉到的密码生成RSA密钥,这个问题也应该得到回答,因为如果正确使用它似乎很有用.