I'm trying to extract the data from a .pem certificate with the Crypt::X509 library, but I get an error in object construction. Here is what I'm doing: 1. Read the .pem file's content:

my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, $atime,$mtime,$ctime,$blksize,$blocks) = stat $s_filename; open FILE, "<$s_filename" or die "no such file"; binmode FILE; my $pem_cert; read FILE, $pem_cert, $size; close FILE;

2. Decode the content from base64 to receive the DER formatted content. This is done because the CPAN documentation of the Crypt::X509 library states that it needs to be passed "A variable containing the DER formatted certificate to be parsed":

my $der = MIME::Base64::decode($pem_cert);

3. Call the Crypt::X509 constructor and check for errors:

my $oref_x509= Crypt::X509->new($der); if ( $oref_x509->error ) { warn "Error on parsing certificate: ", $oref_x509->error; }

I get the following error:

Odd number of elements in hash assignment at ..<path>../Crypt/X509.pm +line 95. Use of uninitialized value $end in numeric ge (>=) at ..<path>../Conve +rt/ASN1/_decode.pm line 626. Use of uninitialized value $end in numeric eq (==) at ..<path>../Conve +rt/ASN1/_decode.pm line 63. Error on parsing certificate: decode error at ..<path>../Convert/ASN1/ +_decode.pm line 64.

In reply to Extract data from certificate with Crypt::X509 by LoraIlieva

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.