in reply to Re: 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

Thanks but it still says...

Can't call method "q" without a package or object reference at /usr/lib/perl5/site_perl/5.8.0/Crypt/DSA.pm line 45.

perldoc for Crypt::DSA says about the Key in sign...

  • Key
    The Crypt::DSA::Key object with which the signature will be gener-
    ated. Should contain a private key attribute (priv_key).

    This argument is required.
  • So I think I somehow need to make $key be an object like what I had in the first script. I just don't see a way to do that right now. I'm sure it must be possible.
    • Comment on Re^2: How to Make Crypt::DSA use a your key to sign something

    Replies are listed 'Best First'.
    Re^3: How to Make Crypt::DSA use a your key to sign something
    by zentara (Cardinal) on Feb 23, 2006 at 21:13 UTC
      Yeah, I just got all the pre-requisites installed, and see the problem in my testing....sorry if I led you off track. After a groups.google.search for the problem, it has been asked before on the newsgroups. What it seems to come down to, is that you cannot just take the Dump
      $key{"priv_key"} = "864936564936746739711078786791024560681741810216";
      and use that as a private key. The "key" must be a Crypt::DSA::Key object. From the looks of things, you need to save your key to a file, like
      $key->write( Type => 'PEM', Filename => $keyfile);
      then when you want to import that file
      $key = Crypt::DSA::Key->new(Type => 'PEM', Filename => $keyfile);
      Now whether you can read that into a scalar value, I don't know. But the PEM key should look like
      -----BEGIN DSA PRIVATE KEY----- MIH3AgEAAkEAuu/8bF0QtFaU8Eo3XzJzyuwyfIEoCvYxzcx5dGkTa7przkVGPaJp n6uEPIueBQEP21+SmfebPpkbKF98gw+MSwIVAMGFQpGtsAWNedBzQ85p0CkTuKYZ AkBLciRf48J8u/LYz2FejmaPs88sKPt/mNLLfzOUz6LO0HqjXOq6vD0WzGcek0Z6 VK9JD3r9eyclPNvsArZ7v/LaAkBxM58UjEqschS9r7Je28kCQ4eYC4lhkRq+pAot /kh86LBlohQZ6A6zgCyPiKNLT5VQ29vKW49f36XjYrIDUk21AhQdRFsMvKVp+W5C 7L7i0FLp3tYb6w== -----END DSA PRIVATE KEY-----
      and NOT the number string you originaly had. I will post an example if I can get it to work. :-)

      I'm not really a human, but I play one on earth. flash japh

        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!

          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
          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.