From flyaflyaa at GMAIL.COM Fri Feb 27 13:37:26 2009 From: flyaflyaa at GMAIL.COM (flya flya) Date: Fri, 27 Feb 2009 20:37:26 +0800 Subject: [PYTHON-CRYPTO] How to get exponent from a PKey object? Message-ID: <5916e1f60902270437n6ef9be85sb8716df2045fd486@mail.gmail.com> 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? From mads at KIILERICH.COM Fri Feb 27 14:06:08 2009 From: mads at KIILERICH.COM (Mads Kiilerich) Date: Fri, 27 Feb 2009 14:06:08 +0100 Subject: [PYTHON-CRYPTO] How to get exponent from a PKey object? In-Reply-To: <5916e1f60902270437n6ef9be85sb8716df2045fd486@mail.gmail.com> References: <5916e1f60902270437n6ef9be85sb8716df2045fd486@mail.gmail.com> Message-ID: <49A7E540.2050900@kiilerich.com> 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