Hello Monks,

I have been reading the guide to MIX files at https://moddingwiki.shikadi.net/wiki/MIX_Format_(Westwood) and have been having a go at decoding some. My problem is dealing with the RSA encrypted header using Crypt:Openssl::RSA, specifically loading the key.

The aforementioned site lists the modulus as AihRvNoIbTn85FZRYNZRcT+i6KpU+maCsEqr3Q5q+LDB5tH7Tz2qQ38V and the private exponent as AigKVje8mROcR8QixnxUEF5b29Curkq01DNDWCdOG99XBqH79OaCiTCB (both as BASE64 / DER encoded integers) and the public exponent as 0x10001. This not being the most helpful format, I figured that the best way to get it into Crypt::Openssl::RSA was via the new_key_from_parameters() method.

I converted both the modulus and private exponent to hex via an online decoder for use with Crypt::OpenSSL::Bignum->new_from_hex.

The issue appears to be that after loading the key material, check_key returns false, triggering the die with "invalid key"

#!/usr/bin/perl use strict; use warnings; use Crypt::OpenSSL::Bignum; use Crypt::OpenSSL::RSA; my $pub = '51BCDA086D39FCE4565160D651713FA2E8AA54FA6682B04AABDD0E6AF8B +0C1E6D1FB4F3DAA437F15'; my $priv = '0A5637BC99139C47C422C67C54105E5BDBD0AEAE4AB4D4334358274E1B +DF5706A1FBF4E682893081'; my $expo = '10001'; my $n = Crypt::OpenSSL::Bignum->new_from_hex($pub); my $e = Crypt::OpenSSL::Bignum->new_from_hex($expo); my $d = Crypt::OpenSSL::Bignum->new_from_hex($priv); my $rsa = Crypt::OpenSSL::RSA->new_key_from_parameters($n, $e, $d); die "invalid key" unless $rsa->check_key;

There doesn't appear to be a lot to screw up, so I can't see where I've got it wrong, unless I've done something stupid decoding the BASE64/DER data. I've been over it several times. If anyone can offer any words of wisdom, I would be extremely grateful.

Thanks,
BOfH

In reply to Importing keys into Crypt::Openssl::RSA by BOfH

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.