Segmentation Fault with RSA.RSA.public_encrypt

"Kershaw, PJ (Philip)" <[email protected]> Fri, 1 Aug 2008 16:17:00 +0100
Newsgroups gmane.comp.python.cryptography
Message-ID <EB1E7CB92F5B35459E0B926D2A614DB602504C27@EXCHANGE19.fed.cclrc.ac.uk>
Hi all,
 
I've got a suspected problem with RSA.RSA.public_encrypt.  If I load a public key from an X.509 cert. PEM file and then try and encrypt something I get a segmentation fault.  If I comment out a call to check_key:
 
    def public_encrypt(self, data, padding):
        #assert self.check_key(), 'key is not initialised'
        return m2.rsa_public_encrypt(self.rsa, data, padding)

... all works OK.  Here's the code I used to test:
from M2Crypto import X509, RSA

text = 'Hello world'
x509Cert = X509.load_cert('./test.crt')
rsaPubKey = x509Cert.get_pubkey().get_rsa()
encrypted = rsaPubKey.public_encrypt(text, RSA.pkcs1_padding)

priKey = RSA.load_key('./test.key')
decrypted = priKey.private_decrypt(encrypted, RSA.pkcs1_padding)

print decrypted

Is it a bug or have I used the API wrongly?

Cheers,
Phil