in reply to Convert::PEM and BIT STRING

Hi, yeah I see your problem, you can get the BIT STRING but it is unknowable, as to what it is. I didn't have your key, so I had to make my own. I don't know how to use the BIT STRING instead of the keys. Here is a simple example that shows how dereferencing 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); 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

#!/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__
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.

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.


I'm not really a human, but I play one on earth Remember How Lucky You Are