XML-Enc
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/XML/Enc.pm view on Meta::CPAN
## Populate:
## self->{KeyInfo}
## self->{key_obj}
## self->{key_type}
##
sub _load_rsa_key {
my $self = shift;
my ($key_text) = @_;
eval {
require Crypt::PK::RSA;
};
confess "Crypt::PK::RSA needs to be installed so that we can handle RSA keys." if $@;
my $rsaKey = Crypt::PK::RSA->new(\$key_text );
if ( $rsaKey ) {
$self->{ key_obj } = $rsaKey;
$self->{ key_type } = 'rsa';
if (!$self->{ x509 }) {
my $keyhash = $rsaKey->key2hash();
$self->{KeyInfo} = "<dsig:KeyInfo>
<dsig:KeyValue>
<dsig:RSAKeyValue>
<dsig:Modulus>$keyhash->{N}</dsig:Modulus>
<dsig:Exponent>$keyhash->{d}</dsig:Exponent>
</dsig:RSAKeyValue>
</dsig:KeyValue>
</dsig:KeyInfo>";
}
}
else {
confess "did not get a new Crypt::PK::RSA object";
}
}
##
## _load_x509_key($key_text)
##
## Arguments:
## $key_text: string RSA Private Key as String
##
## Returns: nothing
##
## Populate:
## self->{key_obj}
## self->{key_type}
##
sub _load_x509_key {
my $self = shift;
my $key_text = shift;
eval {
require Crypt::OpenSSL::X509;
};
confess "Crypt::OpenSSL::X509 needs to be installed so that we
can handle X509 Certificates." if $@;
my $x509Key = Crypt::OpenSSL::X509->new_private_key( $key_text );
if ( $x509Key ) {
$x509Key->use_pkcs1_padding();
$self->{ key_obj } = $x509Key;
$self->{key_type} = 'x509';
}
else {
confess "did not get a new Crypt::OpenSSL::X509 object";
}
}
##
## _load_cert_file()
##
## Arguments: none
##
## Returns: nothing
##
## Read the file name from $self->{ cert } and
## Populate:
## self->{key_obj}
## $self->{KeyInfo}
##
sub _load_cert_file {
my $self = shift;
eval {
require Crypt::OpenSSL::X509;
};
die "Crypt::OpenSSL::X509 needs to be installed so that we can handle X509 certs.\n" if $@;
my $file = $self->{ cert };
if (!-r $file) {
die "Could not find certificate file $file";
}
open my $CERT, '<', $file or die "Unable to open $file\n";
my $text = '';
local $/ = undef;
$text = <$CERT>;
close $CERT;
my $cert = Crypt::PK::RSA->new(\$text);
die "Could not load certificate from $file" unless $cert;
$self->{ cert_obj } = $cert;
my $cert_text = $cert->export_key_pem('public_x509');
$cert_text =~ s/-----[^-]*-----//gm;
$self->{KeyInfo} = "<dsig:KeyInfo><dsig:X509Data><dsig:X509Certificate>\n"._trim($cert_text)."\n</dsig:X509Certificate></dsig:X509Data></dsig:KeyInfo>";
return;
}
sub _create_encrypted_data_xml {
my $self = shift;
local $XML::LibXML::skipXMLDeclaration = $self->{ no_xml_declaration };
my $doc = XML::LibXML::Document->new();
my $xencns = 'http://www.w3.org/2001/04/xmlenc#';
my $dsigns = 'http://www.w3.org/2000/09/xmldsig#';
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.628 second using v1.00-cache-2.02-grep-82fe00e-cpan-f73e49a70403 )