Data Signatures Using Perl

I was this project, which includes sending signed data.

I am provided with a .pem file and a server certificate, which I must import to another server from which I must sign the data using these files, and then send the signed data to another server for verification and processing.

My questions:

  • How to import these two files to my server?
  • How to use perl to use files for data signing?

To note, I have to import into Linux (Suse).

This is what I have done so far. I added the .pem file to / etc / ssl. I use the code below to read from the .pem file and then sign the data

my $rsa = new Crypt::RSA; my $file = 'path to file'; my $key = new Crypt::RSA::Key::Private( Filename => $file , Password => "*****"); my $signature = $rsa->sign(Message => $data, Key => $key, Armour => 0); 

I get errors when I try to run a script, as shown below A bug was found where the operator was expecting in line (eval 30) 4, next to "/ S2YUeaABL1sO3rk4HhjyDSMIJoc91n .....

I noticed that the contents of the .pem file has slashes in the file that causes this problem. see sample

 -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQCMdoWd+LEk22TMaEihLqwl8tJtuFzndJ8dTGrLw6twjfAeV0sg PsDQbVu5/S2YUeaABL1sO3rk4HhjyDSMIJoc91nfE3kYueRxEA9eL5JlxPDg2Z3s 
+1
source share
2 answers
  • Read Import Certificates and Private Key with Copy and Paste

  • RSA login to Perl (unverified code):

     use Crypt::OpenSSL::RSA; use File::Slurp; my $keystring = read_file('private_key.pem'); my $private_key = Crypt::OpenSSL::RSA->new_private_key($keystring); $private_key->use_md5_hash(); # use_sha1_hash is the default my $signature = $private_key->sign($plaintext); 

Good luck

+1
source

Thank you for working now. I used your example with a few changes below

 use File::Slurp qw(read_file); use MIME::Base64 qw(encode_base64); require Crypt::OpenSSL::RSA; my $keystring = read_file( 'path to file name' ); my $privatekey = Crypt::OpenSSL::RSA->new_private_key($keystring); $privatekey->use_pkcs1_padding(); my $signature = $privatekey->sign($datatosign); print encode_base64($signature, ''); 
0
source

Source: https://habr.com/ru/post/980291/


All Articles