Re: Using Crypt::DSA
- From: "Sisyphus" <sisyphus1@xxxxxxxxxxxxxxxxx>
- Date: Fri, 26 Aug 2005 16:50:54 +1000
"Mike Friedman" <mikef@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
>
> So, once again, assuming I've signed a message, creating a signature
> object, how do I write that signature to a file so it can be used
> as input to a verify script?
>
It may simply be that you failed to bless() the key and signature retrieved
from file. Here's a script that writes to file, then reads from that file
and verifies the message using information obtained only from that file:
use strict;
use warnings;
use Crypt::DSA;
my $message = "Je suis l'homme a tete de chou.";
for (1..4) {$message .= "\n$message"}
my $dsa = Crypt::DSA->new;
my $key = $dsa->keygen( Size => 512 );
my $sig = $dsa->sign( Message => $message, Key => $key );
# @file contains all of the signature and key information that
# needs to be written to the file.
my @file = ($key->{p}, $key->{q}, $key->{g}, $key->{pub_key},
$sig->{r}, $sig->{s});
# Save @file and $message to file:
open(WR, ">msg.txt") or die "Can't open WR:$!";
for(@file) {print WR $_, "\n"}
print WR $message;
close(WR) or die "Can't close WR: $!";
# Retrieve key, signature and message from file
open(RD, "msg.txt") or die "Can't open RD:$!";
my @msg_from_file = <RD>;
close(RD) or die "Can't close RD: $!";
my %key_from_file;
my %sig_from_file;
$key_from_file{p} = shift(@msg_from_file);
chomp($key_from_file{p});
$key_from_file{q} = shift(@msg_from_file);
chomp($key_from_file{q});
$key_from_file{g} = shift(@msg_from_file);
chomp($key_from_file{g});
$key_from_file{pub_key} = shift(@msg_from_file);
chomp($key_from_file{pub_key});
$sig_from_file{r} = shift(@msg_from_file);
chomp($sig_from_file{r});
$sig_from_file{s} = shift(@msg_from_file);
chomp($sig_from_file{s});
my $message_from_file;
for(@msg_from_file) {$message_from_file .= $_}
my $k = \%key_from_file;
bless($k, "Crypt::DSA::Key");
my $s = \%sig_from_file;
bless($s, "Crypt::DSA::Signature");
# Verify using data read from file:
my $dsa_verify = Crypt::DSA->new;
my $verified = $dsa_verify->verify(
Key => $k,
Message => $message_from_file,
Signature => $s
);
if($verified) {print "Message verified\n"}
else {print "Message NOT verified\n"}
__END__
Cheers,
Rob
.
- Follow-Ups:
- Re: Using Crypt::DSA
- From: Mike Friedman
- Re: Using Crypt::DSA
- From: Sisyphus
- Re: Using Crypt::DSA
- References:
- Using Crypt::DSA
- From: Mike Friedman
- Re: Using Crypt::DSA
- From: A. Sinan Unur
- Re: Using Crypt::DSA
- From: Mike Friedman
- Re: Using Crypt::DSA
- From: Sisyphus
- Re: Using Crypt::DSA
- From: Mike Friedman
- Using Crypt::DSA
- Prev by Date: and I gave up the shebang line too
- Next by Date: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.5 $)
- Previous by thread: Re: Using Crypt::DSA
- Next by thread: Re: Using Crypt::DSA
- Index(es):
Relevant Pages
|