[PYTHON-CRYPTO] M2Crypto convert key from PEM to DER ?
Hans Lellelid
hans at VELUM.NET
Wed Apr 8 16:49:30 CEST 2009
Ah, perfect; thanks. I don't know why that escaped me; I think the
suggestion of "key pairs" seemed like something different from what I
wanted.
Thanks for the tip -
Hans
On Wed, 8 Apr 2009 08:54:01 +0100, "Kershaw, PJ (Philip)"
<philip.kershaw at stfc.ac.uk> wrote:
> Hi Hans,
>
> If you want to use M2Crypto :) you could do:
>
> from M2Crypto import RSA
> key = RSA.load_key('input.key')
> key.save_key_der('output.key')
>
> Cheers,
> Phil
>
>> -----Original Message-----
>> From: generic crypto class API for Python
>> [mailto:PYTHON-CRYPTO at NIC.SURFNET.NL] On Behalf Of Hans Lellelid
>> Sent: 08 April 2009 01:42
>> To: PYTHON-CRYPTO at NIC.SURFNET.NL
>> Subject: Re: M2Crypto convert key from PEM to DER ?
>>
>>
>> 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
>>
> --
> Scanned by iCritical.
More information about the python-crypto
mailing list