RSA verification problem

RSA verification problem

Secure Home | Search | About
 General Computer Security    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content add this group's latest topics to your Google content
Subject Author Date
RSA verification problem PaulOak 05-11-2006
Posted by PaulOak on May 11, 2006, 8:29 am
If you were  Registered and logged in, you could reply and use other advanced thread options
Hi all,

First of all, sorry if this is not the right place for asking.

I have the following problem:

I need to write a PHP script which verifies a RSA signature. The
problem is that this RSA signature is created using advapi.dll part of
MS CryptoAPI under Windows 2000 (VB6).
The Public key has the length of 1024bits and both together with the
signature are in Base64 format. After spending some time researching
the topic I found out the following:
The Public Key created using MS CryptoAPI is in Base64 format.
Converted to byte array it has a length of 148 Bytes. Which are:
=B7        0 - 11 : Asymmetric algorithm used for encryption
=B7        12 - 15 : Modulus Bit length. Usually (0, 0, 4, 0) =3D 1024 bits /
8 =3D 128 bytes
=B7        16 - 19 : Exponent, usually the default one is (0, 1, 0, 1) =3D
65537
=B7        20 - 147 : Modulus
I wrote a C# code which extracts modulus and exponent and encodes them
in Base64:

// Get Exponent
for (int i =3D 0; i < 4; i++)
{
        bExponent[i] =3D bPublicKey[16 + i];
}

// Get Modulus Bit Length
for (int i =3D 0; i < 4; i++)
{
        bModulusLength[i] =3D bPublicKey[12 + i];
}

Array.Reverse(bModulusLength);

iModulusLength =3D (bModulusLength[0] << 24) | (bModulusLength[1] << 16)
| (bModulusLength[2] << 8) | bModulusLength[3];

// Get Modulus
bModulus =3D new byte[iModulusLength / 8];
for (int i =3D 0; i < iModulusLength / 8; i++)
{
        bModulus[i] =3D bPublicKey[20 + i];
}

Console.WriteLine("Exponent as Base64: " +
Convert.ToBase64String(bExponent) + "\n");

Console.WriteLine("Modulus as Base64: " +
Convert.ToBase64String(bModulus) + "\n");

After extracting the Modulus and the Exponent from the public key I
write the following PHP code (using Crypt_RSA package, part of PEAR
Framework) trying to decrypt the signature, which later must be
verified:

// include PEAR Crypt_RSA
require_once('Crypt\ RSA.php');

$publicKey =3D Crypt_RSA_Key::factory(base64_decode($modulus),
base64_decode($exponent), "public"); if (PEAR::isError($publicKey)) {
echo "error: ", $publicKey>getMessage(), "\ n"; }

// create new Crypt_RSA Object
$rsa_obj =3D &Crypt_RSA::factory(); if (PEAR::isError($rsa_obj)) { echo
"error: ", $rsa_obj->getMessage(), "\ n"; }

$plaintext =3D $rsa_obj->decrypt($signature, $publicKey);


And here I am stuck. When I reverse the byte order of modulus and
exponent I got a public key which has a length of 1023bits. If I do not
reverse them I got a public key which has a length of 1024bits and
after applying this key to decrypt function together with the signature
I do not receive the MD5 hash but a 126 byte long string.

I do not know if you have already had this problem trying to
synchronize signature verification between MS CryptoAPI, which
obviously does not follow the industry standards and other Crypto
providers=20


Any help will be really appreciated.

10x,
Paul


Similar ThreadsPosted
Problem K9 August 23, 2004, 8:36 pm
Deleted IE - now got a big problem August 9, 2004, 11:13 pm
NTFS Problem April 29, 2005, 1:49 pm
Off Topic - DNS Problem February 2, 2006, 5:58 pm
Hacker Problem September 25, 2006, 7:10 am
IP spoofer problem March 2, 2007, 4:37 pm
telnet password problem June 26, 2004, 10:46 am
iKey 1000 - OS PIN problem August 12, 2004, 10:35 am
Post your problem at www.innoengineer.com November 29, 2004, 8:01 pm
ad-aware problem = reformat? February 18, 2005, 10:51 am

The site map in XML format XML site map

Contact Us | Privacy Policy