I am using below module in python for rsa
encryption.
https://github.com/sybrenstuvel/python-rsa
it can be installed by pip as follows pip3 install rsa
I have read of using this module here: https://github.com/sybrenstuvel/python-rsa/blob/master/doc/usage.rst
and I am able to generate public and private key and also able to encrypt the message using public key using the following code
import rsa
pubKey, priKey = rsa.newkeys(1024)
print("Public key: ",pubKey)
print("Private key: ",priKey)
msg = "vinay kumar shukla".encode('utf8')
print("Message without encryption:",msg)
msgEnc = rsa.encrypt(msg, pubKey)
print("encrypted message:",msgEnc)
but I want to store the private key into some file, As you can read in the usage file of this module, they have provide the method to read the key from the .pem
file so it means I should store the keys also in pem
file but I am not getting how can I store the key generated by this module into the file.
When I print the private key generated by this module, It gives me the following output
PrivateKey(8647494628885176696347621451257950700244697066080136004727560667550523829374958314554596272099668415472356485265099323795859891239567212729331504592847959, 65537, 80620400968137738399200401402545247384675983145016755403642821122013062179228267902734675759971390409853232911734749752372599473758015795215587460952985, 6068766834338315918835399238932380729501892761840591316766866213831546939444337723, 1424917922362067845458877023625137340152906787710542109910805914692739733)
And to store this key if i create a file key.pem
and store this key into the file. The content of the file are
-----BEGIN RSA PRIVATE KEY-----
PrivateKey(8647494628885176696347621451257950700244697066080136004727560667550523829374958314554596272099668415472356485265099323795859891239567212729331504592847959, 65537, 80620400968137738399200401402545247384675983145016755403642821122013062179228267902734675759971390409853232911734749752372599473758015795215587460952985, 6068766834338315918835399238932380729501892761840591316766866213831546939444337723, 1424917922362067845458877023625137340152906787710542109910805914692739733)
-----END RSA PRIVATE KEY-----
and when I try to read it it gives me error like padding error etc
please tell me how can i store these keys and then read it to for decryption purpose.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…