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

In reply to Re: Convert::PEM and BIT STRING by zentara
in thread Convert::PEM and BIT STRING by droopycom

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.