Test again your chain programming way , because : >>> dir(RSA.importKey) ['__call__', '__class__', '__cmp__', '__delattr__', '__doc__', '__format__', '__func__', '__get__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'im_class', 'im_func', 'im_self'] >>> dir(RSA.importKey.decrypt()) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'function' object has no attribute 'decrypt'
On Tuesday, June 6, 2017 at 9:29:52 AM UTC+3, Ho Yeung Lee wrote: > i use wb to write pubic and private key > and succeed to import private, but after decrypt, it return hex number > not a clear text > is there any more key needed? > or do wb influence the result? > > from Crypto.PublicKey import RSA > keypair = RSA.generate(2048) > alice_privkey = keypair.exportKey('PEM', 'mysecret', pkcs=1) > #alice_privkey = keypair.exportKey() > alice_pubkey = keypair.publickey().exportKey() > > text_file = open("alice_pubkey.txt", "wb") > text_file.write(alice_pubkey) > text_file.close() > > keypair = RSA.generate(2048) > bob_privkey = keypair.exportKey('PEM', 'mysecret2', pkcs=1) > #bob_privkey = keypair.exportKey() > bob_pubkey = keypair.publickey().exportKey() > > text_file = open("bob_pubkey.txt", "wb") > text_file.write(bob_pubkey) > text_file.close() > > text_file = open("alice_privkey.pem", "wb") > text_file.write(alice_privkey) > text_file.close() > text_file = open("bob_privkey.pem", "wb") > text_file.write(bob_privkey) > text_file.close() > > > #step 2 > #use alice public key to encrypt > pubkey = RSA.importKey(alice_pubkey) > alice_masterkey = pubkey.encrypt("i am Martin", None) > > text_file = open("alice_masterkey.txt", "w") > text_file.write(bob_pubkey) > text_file.close() > > quit() > python > text_file = open("alice_masterkey.txt", "r") > alice_masterkey=text_file.read() > text_file.close() > text_file = open("alice_privkey.pem", "r") > alice_privkey=text_file.read() > text_file.close() > text_file = open("alice_pubkey.txt", "r") > alice_pubkey=text_file.read() > text_file.close() > > from Crypto.PublicKey import RSA > pubkey = RSA.importKey(alice_pubkey) > privkey = RSA.importKey(alice_privkey,passphrase="mysecret") > encryption_key = privkey.decrypt(alice_masterkey) > encryption_key > > quit() > python > text_file = open("alice_masterkey.txt", "r") > alice_masterkey=text_file.read() > text_file.close() > text_file = open("alice_privkey.pem", "r") > alice_privkey=text_file.read() > text_file.close() > text_file = open("alice_pubkey.txt", "r") > alice_pubkey=text_file.read() > text_file.close() > > from Crypto.PublicKey import RSA > pubkey = RSA.importKey(alice_pubkey) > privkey = RSA.importKey(alice_privkey,passphrase="mysecret") > encryption_key = privkey.decrypt(alice_masterkey) > encryption_key > > >>> encryption_key > 'o\x94\xaeC\xe0S\x81\x05t\xd8\\A\x10?\xd2\xe5\x8c5\xc9\x1d\x14\xc7\xfd)Cs\x8b"cg\x16y\xe2\xf2L\xf1-\x08qHt\x99\xbc\xb5\xf6_\x17c\xd2&Z\x0b\xc5t\t\xe0\x8b\x03G\x10\xce\xd6\xcd\x86\xfc!\xc9i\xa2\xab\x9d\x8a\x92\xfc7 > > g\xa5$\x91\x85\xa2L]I\xd6\xc6\xaez\xed\x01\x95\xee)8z\x18\xc9aag\x97\x97\xb0\\)\xec"\xe4\xbez\xd3\xa8\'k%\x12\x1d\xf9\xf0\x0e\x0c\xcb\xa8\xb1\xe7}\x90\xd3\xcfs@\xc2m\x1a^\x1b0\xa7\xdd\xcd\xea\x1f\xd5\x08\x13+y"]vu\xe3\x9e\xba\x97\x10\x90S\xea\xae1=r4Yp,\xe3\xa9\xc66H\xa7\x95[M|n\x91\x98\x9c,\xc4\xf5\x7f\x8cJ\x03\xba\x04Z0lV\xe1\xd6d\xeec@\xe1\xa0\xec\x81]\xef5\r\x12\x88\xbe/\xfc\xe01\xaacn,\x8a\xe1\x14\x8a\xf4\xd85\xd8\xabD\x137\xe7T\xc4\xc1\x84b.\xd9RZ\x0e\x03#\x1e\x8dl\xe8\xe4N^\r\xf0\x1d\x8c' -- https://mail.python.org/mailman/listinfo/python-list