symgryph has asked for the wisdom of the Perl Monks concerning the following question:
The data:!/usr/bin/perl -w @files = <*.p12>; foreach $file(@files) { $fileconvert=$file; $fileconvert=~s/\.p12//g; `openssl pkcs12 -passin pass:$fileconvert -clcerts -nodes -in $fi +le -out $fileconvert.pem\n"`; } @secondpass = <*.pem>; foreach $secondpass(@secondpass) { $filename=$secondpass; open CERT, "<$filename"; @cert=<CERT>; print @cert; while (@cert =~s/BEGIN RSA PRIVATE KEY(.*?)END RSA PRIVATE KEY//s) + { $code = $1; print "$code.\n"; } }
Bag Attributes localKeyID: 33 32 34 33 39 38 33 33 30 32 36 30 33 friendlyName: verisign class 3 public primary certification author +ity subject=/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification + Authority issuer=/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification +Authority -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- Bag Attributes localKeyID: 31 32 33 33 39 38 33 33 30 22 11 30 34 friendlyName: mycerts.test.com Key Attributes: <No Attributes> -----BEGIN RSA PRIVATE KEY----- THIS IS THE FILE i WANT ... -----END RSA PRIVATE KEY----- Bag Attributes localKeyID: 23 32 34 33 39 38 33 33 44 32 36 30 21 friendlyName: mycerts.test.com subject=/C=US/ST=Somewhere/L=There/O=My Org/OU=Terms of use at www.ver +isign.com/rpa (c)00/CN=MYCERTS.TEST.COM issuer=/O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign Interna +tional Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LIA +BILITY LTD.(c)97 VeriSign -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- Bag Attributes localKeyID: 31 32 34 33 39 38 44 33 30 32 36 30 36 friendlyName: verisign intermediate ca subject=/O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign Intern +ational Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LI +ABILITY LTD.(c)97 VeriSign issuer=/C=US/O=VeriSign, Inc./OU=Class 3 Public Primary Certification +Authority -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE-----
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using Perl to convert pkcs12 certificates to pem format, separate files for public/public keys
by toolic (Bishop) on Jun 04, 2009 at 21:27 UTC |