in reply to Re^3: How to Make Crypt::DSA use a your key to sign something
in thread How to Make Crypt::DSA use a your key to sign something

Ah this does work. I should have check the newsgroups a bit more.

I wish the perldoc for Crypt::DSA had mentioned that there is a write function.

Thanks!

  • Comment on Re^4: How to Make Crypt::DSA use a your key to sign something

Replies are listed 'Best First'.
Re^5: How to Make Crypt::DSA use a your key to sign something
by zentara (Cardinal) on Feb 23, 2006 at 21:35 UTC
    Yeah, here is a working example. This script shows 2 ways, one is saving the key to a file and reading it back in, the other, just hard codes the file contents into a variable. I tried a few things to avoid a temp file, but no luck. There is a Content type for the write, but it dosn't seem to work for \scalar....it still writes a file.
    #!/usr/bin/perl use warnings; use strict; use Crypt::DSA; use Crypt::DSA::Key; my $dsa = Crypt::DSA->new; my $key = $dsa->keygen(Size => 512, Verbosity => 1); $key->write( Type => 'PEM', Filename => 'zsave'); my $sig_msg = 'yadda yaddax yadda'; #my $key1 = Crypt::DSA::Key->new( Type=>'PEM', Filename => 'zsave' ); #this is the Content of the file zsave my $pem = '-----BEGIN DSA PRIVATE KEY----- MIH3AgEAAkEAuu/8bF0QtFaU8Eo3XzJzyuwyfIEoCvYxzcx5dGkTa7przkVGPaJp n6uEPIueBQEP21+SmfebPpkbKF98gw+MSwIVAMGFQpGtsAWNedBzQ85p0CkTuKYZ AkBLciRf48J8u/LYz2FejmaPs88sKPt/mNLLfzOUz6LO0HqjXOq6vD0WzGcek0Z6 VK9JD3r9eyclPNvsArZ7v/LaAkBxM58UjEqschS9r7Je28kCQ4eYC4lhkRq+pAot /kh86LBlohQZ6A6zgCyPiKNLT5VQ29vKW49f36XjYrIDUk21AhQdRFsMvKVp+W5C 7L7i0FLp3tYb6w== -----END DSA PRIVATE KEY-----'; my $key1 = Crypt::DSA::Key->new( Type=>'PEM', Content => $pem ); print "$key1\n"; my $sig = $dsa->sign(Message=>$sig_msg, Key => $key1 );

    I'm not really a human, but I play one on earth. flash japh
      Well, here is a way to avoid the temp file, not in the docs but it works.
      #!/usr/bin/perl use warnings; use strict; use Crypt::DSA; use Crypt::DSA::Key; my $dsa = Crypt::DSA->new; my $key = $dsa->keygen(Size => 512, Verbosity => 1); my $pem = $key->write( Type => 'PEM'); print "pem-> $pem\n"; my $sig_msg = 'yadda yaddax yadda'; my $key1 = Crypt::DSA::Key->new( Type=>'PEM', Content => $pem ); print "$key1\n"; my $sig = $dsa->sign(Message=>$sig_msg, Key => $key1 );

      I'm not really a human, but I play one on earth. flash japh
Re^5: How to Make Crypt::DSA use a your key to sign something
by PodMaster (Abbot) on Feb 24, 2006 at 07:34 UTC
    Ah this does work. I should have check the newsgroups a bit more.

    I wish the perldoc for Crypt::DSA had mentioned that there is a write function.

    The Crypt::DSA doc says
    $signature = $dsa->sign(%arg) Signs a message (or the digest of a message) using the private portion of the DSA key and returns the signature.

    The signature is a hash reference with two keys: s and r.

    %arg can include:
    Digest

    A digest to be signed. The digest should be 20 bytes in length or less. You must provide either this argument or Message (see below).

    Key

    The Crypt::DSA::Key object with which the signature will be generated. Should contain a private key attribute (priv_key). This argument is required.

    write (what zentara used), is a method of $key, a Crypt::DSA::Key object, so it makes sense that its documented in Crypt::DSA::Key.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.