I can dump the data, but it doesnt really help me figuring out how a ASN.1 bitstring is stored in a perl variable.

The minimal example (The "key.pem.pub" file is the public part of an RSA key generated by openssl genrsa).

#!/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.pem.pub") or die "Decryption failed: ", $pem->errstr; print "$key->{algorithm}\n"; print "$key->{subjectPublicKey}\n"; print Dumper($key->{subjectPublicKey});
The output is (as seen in vi) not very pretty :
HASH(0x9745798) ARRAY(0x97457a8) $VAR1 = [ '0<82>^A^H^B<82>^A^A^@²tº]u<9b>|M?)^?Ræ<9c>Úö)B<86>úçh<99>< +94>ñ7^P«®Êð<83>r^XßNϵd<86>D^K^V^Bý^A^G AÿÒN©<99>ï¨:<9b><94>^^k <85>xö4*%ÿ§^Sö<91>º"<83> a^S<82>Ö³[u.×Ù<86>FQ<82>ËN^F#ê<9b>·¼Ô0^\iºÍCt¡ý<8f>õë!4Wc<95> Àêá÷^W +7>åé<  ^SùD^\*¤<96>Ñ^¯<92>Á^_«Ö1RZ<81>^N^Q<82><83> ^A!^O^A^QÙz}Ù°ï< ï¼<9e>ä^XZu1r^Wæ^_ç¡ê¼<94>]^F<83>éûvô<8c>¸ùüý<99>fÿ\\7v<83>Ù<91><89>8< +96>~<96>b<8e>ßÞ$;r<91>Ê4ßÞ\'̲)þ^Fl~õ]Êá]`20ý^?^^¿.!òzy0<9a>^L<90><80 +><9f>e<9b>^B^A#', 2144 ];
The BIT STRING is supposed to be the DER encoding of some other ASN.1 structure.

Thank you.


In reply to Re^2: Convert::PEM and BIT STRING by droopycom
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.