[pycrypto] Public Key (X.509) in Modulus/Exponent Format

Legrandin helderijs at gmail.com
Fri Feb 7 02:52:49 PST 2014


Hi,

This answer on stackoverflow shows how you can read the RSA public key
embedded in a PEM X.509 certificate:

http://stackoverflow.com/questions/12911373/how-do-i-use-a-x509-certificate-with-pycrypto

Once you have loaded the RSA public key, you can get modulus and
exponent in the way you need with something like this:

from Crypto.Util.number import long_to_bytes
import base64

for part in rsa_key.n, rsa_key.e:
    print base64.b64encode(long_to_bytes(part))

2014-02-07 5:10 GMT+01:00 Anurag Chourasia <anurag.chourasia at gmail.com>:
> Hi All,
>
> Is it possible to get a Modulus Exponent representation of the public key
> (X.509) using PyCrypto?
>
> For example, the X.509 is
>
> -----BEGIN CERTIFICATE-----
> MIICLDCCAZWgAwIBAgIQRjRrx4AAVrwR024uxBCzsDANBgkqhkiG9w0BAQUFADAS
> MRAwDgYDVQQDEwdDYXJsUlNBMB4XDTk5MDkxOTAxMDg0N1oXDTM5MTIzMTIzNTk1
> OVowEzERMA8GA1UEAxMIQWxpY2VSU0EwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
> AoGBAOCJczmN2PX16Id2OX9OsAW7U4PeD7er3H3HdSkNBS5tEt+mhibU0m+qWCn8
> l+z6glEPMIC+sVCeRkTxLLvYMs/GaG8H2bBgrL7uNAlqE/X3BQWT3166NVbZYf8Z
> f8mB5vhs6odAcO+sbSx0ny36VTq5mXcCpkhSjE7zVzhXdFdfAgMBAAGjgYEwfzAM
> BgNVHRMBAf8EAjAAMA4GA1UdDwEB/wQEAwIGwDAfBgNVHSMEGDAWgBTp4JAnrHgg
> eprTTPJCN04irp44uzAdBgNVHQ4EFgQUd9K00bdMioqjzkWdzuw8oDrj/1AwHwYD
> VR0RBBgwFoEUQWxpY2VSU0FAZXhhbXBsZS5jb20wDQYJKoZIhvcNAQEFBQADgYEA
> PnBHqEjME1iPylFxa042GF0EfoCxjU3MyqOPzH1WyLzPbrMcWakgqgWBqE4lradw
> FHUv9ceb0Q7pY9Jkt8ZmbnMhVN/0uiVdfUnTlGsiNnRzuErsL2Tt0z3Sp0LF6DeK
> tNufZ+S9n/n+dO/q+e5jatg/SyUJtdgadq7rm9tJsCI=
> -----END CERTIFICATE-----
>
> And i need to get to the following representation
>
> <RSAKeyValue>
>   <Modulus>
>
> 4IlzOY3Y9fXoh3Y5f06wBbtTg94Pt6vcfcd1KQ0FLm0S36aGJtTSb6pYKfyX7PqCUQ8wgL6xUJ5GRPEsu9gyz8
>
> ZobwfZsGCsvu40CWoT9fcFBZPfXro1Vtlh/xl/yYHm+Gzqh0Bw76xtLHSfLfpVOrmZdwKmSFKMTvNXOFd0V18=
>   </Modulus>
>   <Exponent>AQAB</Exponent>
> </RSAKeyValue>
>
> Please guide.
>
> Regards,
> Anurag
>
> _______________________________________________
> pycrypto mailing list
> pycrypto at lists.dlitz.net
> http://lists.dlitz.net/cgi-bin/mailman/listinfo/pycrypto
>


More information about the pycrypto mailing list