Various PEM to DER in perl
i have application 开发者_Python百科with client-server architecture.
client (C program):
- generate various DER encoded data
- convert DER to PEM (using openssl's PEM_write_bio) with various PEM header
- send PEM to server
server (Perl script):
- receive PEM data
- convert PEM to DER
- ....
My question is how to convert various PEM data to DER/BER (binary data) in perl?
You can strip off the PEM tags yourself, and do a decode of the Base64 block inside using MIME::Base64
.
Should be as simple as
$derBlob = decode_base64($base64Blob);
An example based on the accepted answer:
#!/usr/bin/perl
use strict;
use warnings;
use MIME::Base64;
my $certPath = 'cert.pem';
open my $fh, '<', $certPath or die(sprintf('Could not open %s file: %s', $certPath, $!));
my $derBlob = do { local $/; decode_base64(<$fh> =~ s/^-.*?\n//gmr); };
close($fh);
print $derBlob;
1;
__END__
精彩评论