[PYTHON-CRYPTO] M2Crypto convert key from PEM to DER ?
Hans Lellelid
hans at VELUM.NET
Wed Apr 8 02:42:21 CEST 2009
Hi -
Mads Kiilerich wrote:
> Hans Lellelid wrote, On 04/08/2009 01:02 AM:
>> I'd like to use M2Crypto to to convert a server key from PEM format to
>> DER. Specifically, I'd like to replace the following openssl command:
>>
>> *openssl rsa –in input.key –inform PEM –out output.key –outform DER
>>
>> I think I understand how to do something similar with the certs, but
>> haven't figured out how to do this with just the private key. I'm sure
>> I'm missing something; can anyone provide any tips?
>
> Using M2Crypto for that might be overkill, though it would be nice not
> to have to write it from scratch every time.
>
> Untested and mostly from memory which might be wrong:
>
> pem = open('cert.pem')
> der = ''.join(l.strip() for l in
> pem.read().split('-----')[2].splitlines()).decode('base64')
> open('cert.der', 'w').write(der)
Thank you! -- I guess the better place to start looking would have been
the relationship between PEM and DER :) I will give that a shot.
Thanks,
Hans
More information about the python-crypto
mailing list