使用Perl的数据签名 [英] Data signatures using Perl

查看:129
本文介绍了使用Perl的数据签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参加过这个项目,涉及发送已签名的数据。



我已经获得了一个.pem文件和一个服务器证书,应该将其导入到其中我应该使用这些文件在另一台服务器上签名数据,然后将签名后的数据发送到另一台服务器进行验证和处理。



我的问题是:




  • 如何将这两个文件导入服务器?

  • 如何使用perl来使用文件来签名数据?



请注意,我要导入到Linux(Suse)中。



这是我到目前为止所做的工作。
我已将.pem文件添加到/ etc / ssl
中,我正在使用以下代码从.pem文件中读取内容,然后对数据

  my $ rsa = new Crypt :: RSA; 
我的$ file =文件路径;
my $ key = new Crypt :: RSA :: Key :: Private(Filename => $ file,Password => *****);
my $ signature = $ rsa-> sign(消息=> $ data,Key => $ key,Armor => 0);

当我尝试运行脚本时出现错误,如下所示:
Bareword在操作员期望的位置找到在(eval 30)第4行,靠近 / S2YUeaABL1sO3rk4HhjyDSMIJoc91n .....



我注意到,.pem文件的内容在文件中包含斜线导致这些问题。
请参见示例

  ----- BEGIN RSA私钥----- 
MIICXAIBAAKBgQCMdoWd + LEk22TMaEihLqwl8tJtuFzndJ8dTGrLw6twjfAeV0sg
PsDQbVu5 / S2YUeaABL1sO3rk4HhjyDSMIJoce >
  • 阅读导入带有复制和粘贴的证书和私钥


  • RSA登录Perl(未测试的代码):

     使用Crypt :: OpenSSL :: RSA; 
    使用File :: Slurp;

    我的$ keystring = read_file('private_key.pem');
    我的$ private_key =密码:: OpenSSL :: RSA-> new_private_key($ keystring);
    $ private_key-> use_md5_hash(); #use_sha1_hash是默认的
    我的$ signature = $ private_key-> sign($ plaintext);


  • 祝你好运!


    I have been this project which involves sending of signed data.

    I have been provided with a .pem file and a server certificate which I am supposed to import to another server from which I should sign the data using these files and then send over the signed data to another server for verification adn processing.

    My Questions are:

    • How do I import these two files into my server?
    • How do I use perl to use the files to sign the data?

    To note, I am to import into a linux (Suse).

    This is what I have done so far I have added the .pem file to /etc/ssl I am using the below code to read from the .pem file 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 the script as below Bareword found where operator expected at (eval 30) line 4, near "/S2YUeaABL1sO3rk4HhjyDSMIJoc91n.....

    I have noted that the contents of the .pem file has slashes within the file which is causing these problem. see sample

    -----BEGIN RSA PRIVATE KEY-----
    MIICXAIBAAKBgQCMdoWd+LEk22TMaEihLqwl8tJtuFzndJ8dTGrLw6twjfAeV0sg
    PsDQbVu5/S2YUeaABL1sO3rk4HhjyDSMIJoc91nfE3kYueRxEA9eL5JlxPDg2Z3s
    

    解决方案

    1. Read Import Certificates and Private Key with Copy and Paste

    2. RSA sign in Perl (untested 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!

    这篇关于使用Perl的数据签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆