-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplitpem.pl
More file actions
executable file
·43 lines (35 loc) · 823 Bytes
/
splitpem.pl
File metadata and controls
executable file
·43 lines (35 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl
#use strict;
use warnings;
sub usage {
$0 =~ /([^\/]+)$/;
my $name = $&;
print "$name [certfile]
break off the key from certfile
write certfile.pem, write certfile.key
defaults to STDIN and STDOUT\n";
exit 1;
}
if ( !defined $ARGV[0] ) {
usage;
}
open (STDI, "$ARGV[0]") or die "Can't open your lame input file: $!";
open (PEMFILE, ">$ARGV[0].pem") or die "Can't open $ARGV[0].pem for output: $!";
open (KEYFILE, ">$ARGV[0].key") or die "Can't open $ARGV[0].pem for output: $!";
my $section=0;
while (<STDI>) {
if ( $_ =~ m/^-----BEGIN.*PRIVATE KEY-----$/ ) {
$section=1;
}
chomp $_;
# next if $_ =~ /^\s*$/;
if ($section == 0) {
print PEMFILE "$_\n";
}
else {
print KEYFILE "$_\n";
}
}
close PEMFILE;
close KEYFILE;
close STDI;