XML Digital Signatures in Perl

I am trying to digitally sign XML in Perl using Crypt::OpenSSL::RSA. I am loading the private key from a file. The private key was created from the keystore using Java.

The following is the Perl code:

my $private = 'my_priv.key';
my $private_key = read_file( $private );
print "my private key text is\n", $private_key;

Conclusion, without putting the whole key here, only the first few lines :-)

> -----BEGIN PRIVATE KEY----- MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKAuqJ1ZkxHZStfSt0CdEsaSYuLO
> 6zDiTpt60asVLWpLe2bf...


my $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($private_key);
print "my private key is\n",$rsa_priv->get_private_key_string();

Conclusion:

> -----BEGIN RSA PRIVATE KEY-----
> MIICXAIBAAKBgQCgLqidWZMR2UrX0rdAnRLGkmLizusw4k6betGrFS1qS3tm3+97
> wMvFXCx0Od8eb

Results $private_keyand $rsa_priv->get_private_key_string()varied. Should he act like that?

Has anyone been able to sign XML with Crypt::OpenSSL::RSA?

edit:

I use Java code to retrieve the private key, the code is as follows: `KeyStore ks = KeyStore.getInstance (" JKS ");

keypass = sPass.toCharArray();

FileInputStream fis = new FileInputStream(store);
ks.load(fis, sPass.toCharArray());
fis.close();

String eol = System.getProperty("line.separator");

Key k = ks.getKey(alias, keypass);

System.out.println("....Generating the Private Key.....");
String encKey = new BASE64Encoder().encode(k.getEncoded());
System.out.println("Encoded Key: " + encKey);
BufferedWriter myKey = null;
myKey = new BufferedWriter(new FileWriter(alias + "_priv.key"));
myKey.write("-----BEGIN PRIVATE KEY-----" + eol);
myKey.write(encKey + eol);
myKey.write("-----END PRIVATE KEY-----");
myKey.close();
System.out.println("....Private Key Generated.....");`

using java and perl because the xmls I'm trying to sign is in perl (this is a whole big system) and the keystore is in java.

-, xml

+5
1

$private_key; $rsa_priv->get_private_key_string(); , ?

, X509, - RSA-. openssl rsa -in my_priv.key .

, .

+1

All Articles