[PYTHON-CRYPTO] How to get exponent from a PKey object?

Mads Kiilerich mads at KIILERICH.COM
Fri Feb 27 14:06:08 CET 2009


flya flya wrote:
> I need read the public key from  certificate, I can get a PKey object
> use follow codes:
>     from M2Crypto import X509
>     cer = X509.load_cert('test.pem', X509.FORMAT_PEM)
>     pk = cer.get_pubkey()
> and use pk.get_modulus() to get the modulus, but how can I get exponent?
> I need these  two values to make a new public key struct , and use it
> as a param to call a function from a dll file using ctypes. I found E
> is often 65537, but I ask a university teacher, he say it can be any
> value, so how can I get it?
>   

When I looked at it briefly some time ago I concluded that 
pk.get_rsa().pub() was the best option. The prefixes there doesn't look 
like anything I have seen before, but adding and removing them is an 
easy and ugly hack.

(The question is slightly similar to 
http://article.gmane.org/gmane.comp.python.cryptography/524 - and the 
answer might be the same ;-) )

/Mads



More information about the python-crypto mailing list