FW: M2Crypto convert key from PEM to DER ?

"Kershaw, PJ (Philip)" <[email protected]> Wed, 8 Apr 2009 09:07:20 +0100
Newsgroups gmane.comp.python.cryptography
Message-ID <EB1E7CB92F5B35459E0B926D2A614DB605B5D901@EXCHANGE19.fed.cclrc.ac.uk>
> -----Original Message-----
> From: Kershaw, PJ (Philip)=20
> Sent: 08 April 2009 08:54
> To: 'Hans Lellelid'
> Cc:=20
> Subject: RE: M2Crypto convert key from PEM to DER ?
>=20
>=20
> Hi Hans,
>=20
> If you want to use M2Crypto :) you could do:
>=20
> from M2Crypto import RSA
> key =3D RSA.load_key('input.key')
> key.save_key_der('output.key')
>=20
> Cheers,
> Phil
>=20
> > -----Original Message-----
> > From: generic crypto class API for Python
> > [mailto:[email protected]] On Behalf Of Hans Lellelid
> > Sent: 08 April 2009 01:42
> > To: [email protected]
> > Subject: Re: M2Crypto convert key from PEM to DER ?
> >=20
> >=20
> > Hi -
> >=20
> > 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 =96in input.key =96inform PEM =96out output.key=20
> =96outform 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?
> > >=20
> > > Using M2Crypto for that might be overkill, though it would
> > be nice not
> > > to have to write it from scratch every time.
> > >=20
> > > Untested and mostly from memory which might be wrong:
> > >=20
> > > pem =3D open('cert.pem')
> > > der =3D ''.join(l.strip() for l in
> > > pem.read().split('-----')[2].splitlines()).decode('base64')
> > > open('cert.der', 'w').write(der)
> >=20
> > Thank you!  -- I guess the better place to start looking
> > would have been=20
> > the relationship between PEM and DER :)  I will give that a shot.
> >=20
> > Thanks,
> > Hans
> >=20
>=20
-- 
Scanned by iCritical.