#!/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); printf "Public key: %s\n", $key->pub_key; my $pem = $key->write( Type => 'PEM', Filename => 'zsave1'); print "pem-> $pem\n"; #show that the file saved as private key contains all #information my $pem1 = Convert::PEM->new( Name => "DSA PRIVATE KEY", ASN => qq( DSAPrivateKey SEQUENCE { version INTEGER, p INTEGER, q INTEGER, g INTEGER, pub_key INTEGER, priv_key INTEGER } )); my $pkey = $pem1->read( Filename => 'zsave1' ); my %deref = %$pkey; for(keys(%deref)) {print "\n$_: $deref{$_}\n"} print "\n"; my %d = %{$deref{DSAPrivateKey}}; for (keys(%d)) {print "$_ : $d{$_}\n"} __END__
I had a key_pub and key_priv pair that test with, and ran your script on it
It gives me the same BIT STRING, but I don't know what it is. Googling for "subjectPublicKey BIT STRING " gives some details. My best guess is that you will have to read something like X.509 specs, and figure out the BIT STRING structure, then unpack the binary data we see in the dumps.#!/usr/bin/perl -w use Data::Dumper; use Convert::PEM; my $pem = Convert::PEM->new( Name => "PUBLIC KEY", ASN => qq( AlgorithmIdentifier ::= SEQUENCE { algorithm OBJECT IDENTIFIER, parameters ANY DEFINED BY algorithm OPTIONAL } SubjectPublicKeyInfo ::= SEQUENCE { algorithm AlgorithmIdentifier, subjectPublicKey BIT STRING } )) or die "New failed: ", Convert::PEM->errstr; my $key = $pem->read(Filename => "key_pub") or die "Decryption failed: ", $pem->errstr; my $aref; my %deref = %$key; for(keys(%deref)) {print "\n$_: $deref{$_}\n"; $aref = $deref{$_}; } print "$aref\n"; print @$aref,"\n"; __END__
Sorry I can't help more. BIT STRING isn't even mentioned in Convert::PEM. It is mentioned in Crypt-DSA-0.13/lib/Crypt/DSA/Key/Pem.pm. I think you will need to figure out what special type of BIT STRING it is, then unpack accordingly.
By the way, where are you getting the public key you are testing from? Is it off of a Blackberry, or something? Add "blackberry" to the search string above and get it's structure.
In reply to Re: Convert::PEM and BIT STRING
by zentara
in thread Convert::PEM and BIT STRING
by droopycom
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |