I've been all over the internet trying to figure out why I get two different results when trying to sign data using Crypt::OpenSSL::RSA and the following command line:

$ printf "$req_data" | openssl rsaautl -sign -inkey ~/.chef/asalvo13.pem | openssl env -base64

I'm trying to write a small interface between a Perl app and the Chef Server REST API. The code below generates the authentication headers to be send. The headers taken from the shell commands, when sent to our Chef server result in a successful request, but the Pure Perl headers do not.

use Crypt::OpenSSL::RSA; use MIME::Base64; use strict; use warnings; my $req_data = qq[Method:GET Hashed Path:1DfW7438O+6WjXaWOV69lrPO5z0= X-Ops-Content-Hash:2jmj7l5rSw0yVb/vlWAYkK/YBwk= X-Ops-Timestamp:2015-08-07T19:32:19Z X-Ops-UserId:asalvo13]; my $keyfile = "$ENV{HOME}/.chef/asalvo13.pem"; my $keystr; open(KEYFILE, "<$keyfile") || die "Cannot open $keyfile: $!\n"; { undef $/; $keystr = <KEYFILE>; close KEYFILE; } my $rsa_priv = Crypt::OpenSSL::RSA->new_private_key($keystr); my $pure_perl = encode_base64($rsa_priv->sign($req_data)); my $shell_cmds = `printf "$req_data" | openssl rsautl -sign -inkey $ke +yfile | openssl enc -base64`; print "=" x 20,"BEGIN PURE PERL","=" x 20,"\n"; print $pure_perl; print "=" x 20,"END PURE PERL","=" x 20,"\n\n"; print "=" x 20,"BEGIN SHELL COMMANDS","=" x 20,"\n"; print $shell_cmds; print "=" x 20,"END SHELL COMMANDS","=" x 20,"\n";

Here's the output:

====================BEGIN PURE PERL==================== Ox4nMjzgrFKSV2GpSH6z80Mbk8zS2gTy0rvN6AyBYM/o9Bw+BbwEa5HuD8v7xlWUkGghE1 +8MT8A4 mkBuTFJlNRimpno1Dj+oifvcpsb1YQ+1uCvyDJAFNjJnlt0S5gDFejHg2Gn8/dp0Lx7dTp +b6QRmk 1+VeKaHMwbkjGlihLNoDftrJlCsAqsQRGM3flXQrdXcOqfSeUVeRrUKzvV6W08i+bTwfvE +ONLqRd kqr3/nem1RuIp7G+BkZezmNdU372iPTf2JPZWtJS9SSTgzM+hzhsY/jEZ48USmjLKUcpHy +55SRhy aH9RpACL5Xfx6nqtK/K5Lk6ZD3x3nVJgVHV29Q== ====================END PURE PERL==================== ====================BEGIN SHELL COMMANDS==================== jjLfh5dprypLNw+5KM2kB0k7ywVBYfL54zLCpgnhmi6xdFqn/CWBwOcOMnOe0Idt CJhm+pkpIucOc/ABbgJ7r5+4r5rp9NvOasNcb9HRX3e8zs4aNQWOXTW8OwGgvw3R PlUAqISW33mwytzcQjzlbQJ5DR/NAzTPBzoD/x/T3a/fuf6CySx0ZtbV0vsq9pBm ekDAdZKS/ssw1OCqowYgdV3jMmcfSlVNnRLb0uY2wVxqhCA6waZ0Qq/DgV5MLRv2 DC9VdpiQJ+tG6L7Ncn8WN0hOY5yIiDpjsXecwNkbkSOoR0pzPe+Z00rsaFMMzFcY TYgeoemNE2uBmFjlmDgF+g== ====================END SHELL COMMANDS====================

Obviously I could simply have my library just make calls out to the shell, but I really would rather not. At the end of it all I'd really like to understand why the difference exists. So any insight would be appreciated.

I'm using..

- Crypt::OpenSSL::RSA version 0.28

- OpenSSL 0.9.8zf 19 Mar 2015

- OS X 10.10.4 (14E46)

- perl 5, version 18, subversion 1 (v5.18.1)


In reply to Difference between Crypt::OpenSSL::RSA and openssl command by naunga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.