How to encrypt using a public key?

msg = "this is msg to encrypt"

pub_key = M2Crypto.RSA.load_pub_key('mykey.py') // This method is taking PEM file.

encrypted = pub_key.public_encrypt(msg, M2Crypto.RSA.pkcs1_padding) 

Now I'm trying to provide a file containing a public key of the radix64 format as a parameter in this method and unable to get the expected result, that is, encryption using a public key of the radix64 format.

Is there any other method in the Python API that can encrypt msg with the public key after trying to use some kind of mechanism?

I get my public key from a public key server with some HTML packaging and in radix64 format. How to convert the public key so that it can be accepted by any encryption method?

+5
source share
3 answers

- , :

M2Crypto.RSA.RSAError: no start line

, unicode. ascii:

key.encode('ascii')
+6
+1

There is an error in the opened key. It appears to be a PGP public key, but with a different string length, so it cannot be used directly as an RSA public key.

0
source

All Articles