Decrypt .NET

Get help with using the PHP Secure Communications Library.

Moderator: Nuxius

Forum rules
The purpose of this forum is to provide support for phpseclib, a pure PHP SSH / SFTP / RSA library.

Posts by new users are held in a moderation queue and are not publicly visible until the post is approved.

Decrypt .NET

Postby rsanubee » Thu Sep 30, 2010 5:27 am

Hello,
I am very new to RSA and I am just wondering if this is the library I need for my issue. I have the Public Key, Private Key and passwords Encrypted with the Public Key all done on microsoft .NET. I just need to be able to decrypt the passwords in PHP. Any help would be so much appreciated...even a pointer in the right direction if this is not the right forum. Here is a sample Public Key, Private Key and encrypted password and thank you in advance:

Public key:
<RSAKeyValue><Modulus>yEQs2LxSHBZgZCH0rRQQy9kmry8g2tNhQL1B9f5azNz9Ce9pXPgSRjVUo1
B9Ggb/FK3jy41wWd2IfS6rse3vBzRsabMj29CVODM/19yZPmwEmjJHCgYd+AA2qweKZanDp4FLsSw/ky
V5WoPN16GHEMLmLGkJFNIWtzzH5jV+S80=</Modulus><Exponent>AQAB</Exponent></RSAKeyVal
ue>


Private key:
<RSAKeyValue><D>p6lD7nPDPlaRfmNbJ6e75B25oEKRfAIp0nxgA6VduVNt2OqByF67VeICKPQSuD6R
QWvPYTPZkrLAOSVggwcS6/Vf1TlqGPD71rDH2V8lAt99glhOxnTrUJ8S948HNwM6vdayciUkGWuFMxp3
M7teiHweqihImUPXF7TZySu0VpU=</D><DP>VUVk1xp4GWcd29PnFWXIaXOuz49T33t0ivUaDSIgQkgv
tNv2USvrtGVob5qwui1OFHpQbCLOV76TGlh1cpyGXQ==</DP><DQ>KWBWLaMdldo5PuYS5L8k3nnn4t4
H1Z5fFRDkfBZyr0DMBBWhrA9sAxGm/CgQT+Egk3UUFrSQzYIq5WOL/3iKjQ==</DQ><InverseQ>shBn
bX+byy+9zxQ0q2oipP0fP+b422vmRzzsspOkfzbvYCx6zANAHFgmJkZZdxmrHUQzZRWWBcRT4TscEy3E
Ag==</InverseQ><P>+SYfJCBnleSlNOjF4CTc3HXJwWNnOyLPkRTl1+snA+iOljHvZSuKT0/s4gTMIA
arFSorw4AzEb8ozTS0Rg3vcw==</P><Q>zcXyDShGa3ZxtGEqmTJYdccCnj7CuPs8GBaQjQOqylWd8/z
ZJDFsBRVK05Ktg8b5ImquNgSTNs0SckYx3iGHvw==</Q></RSAKeyValue>


Encrypted password: kBYpzjoRA9Gv5Gwk63F72V4KRLYvDxhxp7hS0NVPSTTA7IcNSt12tcxMxn6sntwjnla71tSJP8AQjYgOjzic1ctXn1YnH+K6yo8ZIWAglWX+Fg4JTHFBVHnvPmonxYQ/+HdCFdobgx0O+p+HVAoZ3YzOa+o68GZy09bq34Wof5A=
rsanubee
Traveler
 
Posts: 5
Joined: Thu Sep 30, 2010 5:18 am

Re: Decrypt .NET

Postby TerraFrost » Fri Oct 01, 2010 6:14 pm

Is this the plaintext?: "9 2 1 4 8 5 2 "

Here's the script I used to get that:
Code: Select all
<?php
include('Crypt/RSA.php');

$publickey = '<RSAKeyValue>
  <Modulus>yEQs2LxSHBZgZCH0rRQQy9kmry8g2tNhQL1B9f5azNz9Ce9pXPgSRjVUo1B9Ggb/FK3jy41wWd2IfS6rse3vBzRsabMj29CVODM/19yZPmwEmjJHCgYd+AA2qweKZanDp4FLsSw/kyV5WoPN16GHEMLmLGkJFNIWtzzH5jV+S80=</Modulus>
  <Exponent>AQAB</Exponent>
</RSAKeyValue>';

$xml = new DOMDocument();
$xml->loadXML($publickey);

$modulus = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Modulus')->item(0)->nodeValue), 256);
$exponent = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Exponent')->item(0)->nodeValue), 256);

$privatekey = '<RSAKeyValue>
  <D>p6lD7nPDPlaRfmNbJ6e75B25oEKRfAIp0nxgA6VduVNt2OqByF67VeICKPQSuD6RQWvPYTPZkrLAOSVggwcS6/Vf1TlqGPD71rDH2V8lAt99glhOxnTrUJ8S948HNwM6vdayciUkGWuFMxp3M7teiHweqihImUPXF7TZySu0VpU=</D>
  <DP>VUVk1xp4GWcd29PnFWXIaXOuz49T33t0ivUaDSIgQkgvtNv2USvrtGVob5qwui1OFHpQbCLOV76TGlh1cpyGXQ==</DP>
  <DQ>KWBWLaMdldo5PuYS5L8k3nnn4t4H1Z5fFRDkfBZyr0DMBBWhrA9sAxGm/CgQT+Egk3UUFrSQzYIq5WOL/3iKjQ==</DQ>
  <InverseQ>shBnbX+byy+9zxQ0q2oipP0fP+b422vmRzzsspOkfzbvYCx6zANAHFgmJkZZdxmrHUQzZRWWBcRT4TscEy3EAg==</InverseQ>
  <P>+SYfJCBnleSlNOjF4CTc3HXJwWNnOyLPkRTl1+snA+iOljHvZSuKT0/s4gTMIAarFSorw4AzEb8ozTS0Rg3vcw==</P>
  <Q>zcXyDShGa3ZxtGEqmTJYdccCnj7CuPs8GBaQjQOqylWd8/zZJDFsBRVK05Ktg8b5ImquNgSTNs0SckYx3iGHvw==</Q>
</RSAKeyValue>';

$xml = new DOMDocument();
$xml->loadXML($privatekey);

$d = new Math_BigInteger(base64_decode($xml->getElementsByTagName('D')->item(0)->nodeValue), 256);
$dp = new Math_BigInteger(base64_decode($xml->getElementsByTagName('DP')->item(0)->nodeValue), 256);
$dq = new Math_BigInteger(base64_decode($xml->getElementsByTagName('DQ')->item(0)->nodeValue), 256);
$inverseq = new Math_BigInteger(base64_decode($xml->getElementsByTagName('InverseQ')->item(0)->nodeValue), 256);
$p = new Math_BigInteger(base64_decode($xml->getElementsByTagName('P')->item(0)->nodeValue), 256);
$q = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Q')->item(0)->nodeValue), 256);

$rsa = new Crypt_RSA();
$rsa->modulus = $modulus;
$rsa->publicExponent = $exponent;
$rsa->exponents = array(1=> $dp, $dq);
$rsa->coefficients = array(2 => $inverseq);
$rsa->primes = array(1 => $p, $q);
$rsa->k = strlen($rsa->modulus->toBytes());

$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);

$ciphertext = base64_decode('kBYpzjoRA9Gv5Gwk63F72V4KRLYvDxhxp7hS0NVPSTTA7IcNSt12tcxMxn6sntwjnla71tSJP8AQjYgOjzic1ctXn1YnH+K6yo8ZIWAglWX+Fg4JTHFBVHnvPmonxYQ/+HdCFdobgx0O+p+HVAoZ3YzOa+o68GZy09bq34Wof5A=');
echo $rsa->decrypt($ciphertext);
?>
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Decrypt .NET

Postby rsanubee » Sat Oct 02, 2010 3:41 am

Wow. That is so incredible! Yes that is the answer! I am sooooooo happy right now that I am speechless (which if you knew me is rare). Thank you again so much for taking time out of your schedule to help me.
rsanubee
Traveler
 
Posts: 5
Joined: Thu Sep 30, 2010 5:18 am

Re: Decrypt .NET

Postby rsanubee » Sat Oct 02, 2010 8:49 pm

Program works perfectly, but I do not understand why if I echo strlen(echo $rsa->decrypt($ciphertext)); then I get 14? It should only be 7. I tried trim() and it makes no difference so why does php think there are more characters? I found this when I tried to compare the $rsa->decrypt($ciphertext) with the password typed in and it would never validate a match even though when I printed to the screen they look the same. Thank you again.
rsanubee
Traveler
 
Posts: 5
Joined: Thu Sep 30, 2010 5:18 am

Re: Decrypt .NET

Postby TerraFrost » Sat Oct 02, 2010 9:01 pm

bin2hex($rsa->decrypt($ciphertext)) gives 3900320031003400380035003200. ie. there's a null byte between every number. My guess would be that the plaintext, before encryption, is UTF-16 encoded and that after encryption it's ISO-8859-1 encoded. Maybe you can play around with the character encodings some. Or you could just remove every other character.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Decrypt .NET

Postby rsanubee » Sat Oct 02, 2010 9:20 pm

Thank you again. I just made a function for hex2bin and called hex2bin("3900320031003400380035003200") .... a hack, but works:

Code: Select all
function hex2bin($h)
  {
  if (!is_string($h)) return null;
  $r='';
  for ($a=0; $a<strlen($h); $a+=4) { $r.=chr(hexdec($h{$a}.$h{($a+1)})); }
  return $r;
  }
rsanubee
Traveler
 
Posts: 5
Joined: Thu Sep 30, 2010 5:18 am

Re: Decrypt .NET

Postby TerraFrost » Sun Oct 03, 2010 3:12 pm

Here's a function that you might be able to use:

http://www.php.net/manual/en/function.u ... .php#49185

You could maybe try mb_convert_encoding, as well, if it's installed, or maybe the iconv functions.

Maybe deleting every other character is a good solution, too - I don't know. I don't know a whole lot about character encodings lol.
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Decrypt .NET

Postby rsanubee » Mon Oct 04, 2010 1:14 am

Thank you again. Between rsa and character encodings, I feel like I am a rookie programmer. LOL I will benchmark the others to see if any are better or faster than another. In the mean time, the function I have works and thanks to your code, I will meet my deadline for the project I am working on. I will test the others next week. Thanks again.
rsanubee
Traveler
 
Posts: 5
Joined: Thu Sep 30, 2010 5:18 am

Re: Decrypt .NET

Postby shekary_f » Tue Oct 26, 2010 8:53 am

Hello all
I found this class but there is not some of these variables:
$rsa->modulus
$rsa->publicExponent
and
...
and it has not this method :
$rsa->setEncryptionMode(setEncryptionModeCRYPT_RSA_ENCRYPTION_PKCS1);
Have could you help me ?
Do you can send class or download link to me?
tanks
shekary_f
Traveler
 
Posts: 6
Joined: Tue Oct 26, 2010 7:23 am

Re: Decrypt .NET

Postby shekary_f » Tue Oct 26, 2010 3:48 pm

Hello
I tested rsa.php with another pubic and private keys .
And it get to me an error.

Can you tell me who you make public and private keys?
tanks all
shekary_f
Traveler
 
Posts: 6
Joined: Tue Oct 26, 2010 7:23 am

Re: Decrypt .NET

Postby TerraFrost » Wed Oct 27, 2010 1:49 pm

My guess would be that you're using another Crypt_RSA. Like maybe PEAR's or something. If so then the solution would be to download phpseclib's Crypt_RSA. Here's the link:

https://sourceforge.net/projects/phpsec ... p/download
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Decrypt .NET

Postby shekary_f » Wed Oct 27, 2010 3:17 pm

Sorry
My IP Address and Country are blocked and can not download from this link.
I downloaded and used phpseclib-cvs.zip from
http://www.frostjedi.com/terra/dev/phpseclib-cvs.zip
before and it not work.
Can you send this pack to my email:
shekary_f@yahoo.com
Tank you for your reply.
shekary_f
Traveler
 
Posts: 6
Joined: Tue Oct 26, 2010 7:23 am

Re: Decrypt .NET

Postby TerraFrost » Wed Oct 27, 2010 3:39 pm

Code: Select all
<?php
include('Crypt/RSA.php');

$publickey = '<RSAKeyValue>
  <Modulus>yEQs2LxSHBZgZCH0rRQQy9kmry8g2tNhQL1B9f5azNz9Ce9pXPgSRjVUo1B9Ggb/FK3jy41wWd2IfS6rse3vBzRsabMj29CVODM/19yZPmwEmjJHCgYd+AA2qweKZanDp4FLsSw/kyV5WoPN16GHEMLmLGkJFNIWtzzH5jV+S80=</Modulus>
  <Exponent>AQAB</Exponent>
</RSAKeyValue>';

$xml = new DOMDocument();
$xml->loadXML($publickey);

$modulus = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Modulus')->item(0)->nodeValue), 256);
$exponent = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Exponent')->item(0)->nodeValue), 256);

$privatekey = '<RSAKeyValue>
  <D>p6lD7nPDPlaRfmNbJ6e75B25oEKRfAIp0nxgA6VduVNt2OqByF67VeICKPQSuD6RQWvPYTPZkrLAOSVggwcS6/Vf1TlqGPD71rDH2V8lAt99glhOxnTrUJ8S948HNwM6vdayciUkGWuFMxp3M7teiHweqihImUPXF7TZySu0VpU=</D>
  <DP>VUVk1xp4GWcd29PnFWXIaXOuz49T33t0ivUaDSIgQkgvtNv2USvrtGVob5qwui1OFHpQbCLOV76TGlh1cpyGXQ==</DP>
  <DQ>KWBWLaMdldo5PuYS5L8k3nnn4t4H1Z5fFRDkfBZyr0DMBBWhrA9sAxGm/CgQT+Egk3UUFrSQzYIq5WOL/3iKjQ==</DQ>
  <InverseQ>shBnbX+byy+9zxQ0q2oipP0fP+b422vmRzzsspOkfzbvYCx6zANAHFgmJkZZdxmrHUQzZRWWBcRT4TscEy3EAg==</InverseQ>
  <P>+SYfJCBnleSlNOjF4CTc3HXJwWNnOyLPkRTl1+snA+iOljHvZSuKT0/s4gTMIAarFSorw4AzEb8ozTS0Rg3vcw==</P>
  <Q>zcXyDShGa3ZxtGEqmTJYdccCnj7CuPs8GBaQjQOqylWd8/zZJDFsBRVK05Ktg8b5ImquNgSTNs0SckYx3iGHvw==</Q>
</RSAKeyValue>';

$xml = new DOMDocument();
$xml->loadXML($privatekey);

$d = new Math_BigInteger(base64_decode($xml->getElementsByTagName('D')->item(0)->nodeValue), 256);
$dp = new Math_BigInteger(base64_decode($xml->getElementsByTagName('DP')->item(0)->nodeValue), 256);
$dq = new Math_BigInteger(base64_decode($xml->getElementsByTagName('DQ')->item(0)->nodeValue), 256);
$inverseq = new Math_BigInteger(base64_decode($xml->getElementsByTagName('InverseQ')->item(0)->nodeValue), 256);
$p = new Math_BigInteger(base64_decode($xml->getElementsByTagName('P')->item(0)->nodeValue), 256);
$q = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Q')->item(0)->nodeValue), 256);

$rsa = new Crypt_RSA();
$rsa->modulus = $modulus;
$rsa->publicExponent = $exponent;
$rsa->exponents = array(1=> $dp, $dq);
$rsa->coefficients = array(2 => $inverseq);
$rsa->primes = array(1 => $p, $q);
$rsa->k = strlen($rsa->modulus->toBytes());

$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);

$ciphertext = base64_decode('kBYpzjoRA9Gv5Gwk63F72V4KRLYvDxhxp7hS0NVPSTTA7IcNSt12tcxMxn6sntwjnla71tSJP8AQjYgOjzic1ctXn1YnH+K6yo8ZIWAglWX+Fg4JTHFBVHnvPmonxYQ/+HdCFdobgx0O+p+HVAoZ3YzOa+o68GZy09bq34Wof5A=');
echo $rsa->decrypt($ciphertext);
?>

That works fine for me using the version you posted a link to. Can you post the error you're getting?
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Re: Decrypt .NET

Postby shekary_f » Wed Oct 27, 2010 6:43 pm

hi
I find phpseclib0.2.1a.zip in
http://www.mirrorservice.org/sites/ftp. ... 0.2.1a.zip
but when I test it with
(
This keys produced by c# source code:
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
string privateKey = rsa.ToXmlString(true);
string publicKey = rsa.ToXmlString(false);
and encrypt "test" data.
)
public key:


<RSAKeyValue><Modulus>2xrDz/SAJ9QX4qtgnN2E8UlUa5ayPFVhzlv5afeHRL4RDsoqxSDCfL+oZxnZCWAMBNwHeFxcaibhfgG3oXbis8yg5yc5ac22zg26S3fcGaz//LXhG+pApHz/Bt6x7SYeAeZqm9Bpc1dNAOlCRXd/88Q9405s8q1cfqQzM+gU2Dk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>

private key:

<RSAKeyValue><Modulus>2xrDz/SAJ9QX4qtgnN2E8UlUa5ayPFVhzlv5afeHRL4RDsoqxSDCfL+oZxnZCWAMBNwHeFxcaibhfgG3oXbis8yg5yc5ac22zg26S3fcGaz//LXhG+pApHz/Bt6x7SYeAeZqm9Bpc1dNAOlCRXd/88Q9405s8q1cfqQzM+gU2Dk=</Modulus><Exponent>AQAB</Exponent><P>787qpkCapSXhyqks50GHIlnyWL2QGcPHtOhWBmLiOYod1EjrYKM7w5AMN251b+Q/hv4Injbc3LbZzCo49J/75Q==</P><Q>6eX8GJx/9vv8LHwqQEVrYTcAl2uP+4dUkQCCNWTvJoAY2W3LuG8oPbqPzoDLlj/9581xgnI57jkV1g7g/2HtxQ==</Q><DP>Xe0YgReKuqaUwnDysn069ZxvTIyq1TyWiuf5UbUHUGwldNE+x/IHZXiVIFz2SGYI79GuBHIOnbBMrCfZeQ70dQ==</DP><DQ>eyD66OnZ42cbhT+H7nWc5XxS72NMVJkVR5AA+6K60oW0jyFhkSHTCUvg0FC028+sFg7spkMDhAjBGgKTJ12iEQ==</DQ><InverseQ>50MjKmCl9DZjequHmfW3PZ0cwcTLjhakx1qTcl/Xur0SzgdsIW3ncKJVbG7vfpRlHfpH2uNGL7lR66NAj/qI+A==</InverseQ><D>RiTibU/0O0v+PZXp/y434ls8iJkdBI29Gyh8x7zz9ED5CwgT+zoKqY9eJWuz/Plfv6qFRbYj6+P4qrN4C1wZJSkE/vhqHPxdlyNTmoehS0FLiBBhX2EFHg+srU+ArVWTfqrvhJhhacp6R7wzFqgH2W6vixaYrmtln77dR7PI39E=</D></RSAKeyValue>


and Data("test"):
esYXv4ZezAO2k8d6G2ZSwxjvnQcyYpTfBEPcBWUGy7jNJYLvWEfu/aFGB+aPl2jVPVDQCScRTJbpxTYFn/fWq4EeI7Hsly9c6zH/C4+FQbtmw1BTVg9u5DNw31GY/q22eVveHtjgY+An0uG2eLj/jRS2zk5enWkYMrcA/QxobaI=

it show me same error:

Notice: Decryption error in C:\Program Files\Apache Group\Apache2\htdocs\phpseclib2\Crypt\RSA.php on line 1674

Can any one help me ?
Tank you very much.
Attachments
RSAEncryptionTestApplication.rar
(175.71 KiB) Downloaded 285 times
shekary_f
Traveler
 
Posts: 6
Joined: Tue Oct 26, 2010 7:23 am

Re: Decrypt .NET

Postby TerraFrost » Thu Oct 28, 2010 8:50 pm

Dudi Bender's RSA class (ie. the class you're using) employs strictly textbook compliant RSA. It's open to timing attacks and with no random element (as PKCS#1 and OAEP provide) it's easy to see when the same string of plaintext is being reused. RSA has a lot to offer but not as implemented in the class you're using.

None-the-less, to achieve interoperability with that class here's what you'd need to do:

Code: Select all
include('Crypt/RSA.php');

$publickey = '<RSAKeyValue><Modulus>2xrDz/SAJ9QX4qtgnN2E8UlUa5ayPFVhzlv5afeHRL4RDsoqxSDCfL+oZxnZCWAMBNwHeFxcaibhfgG3oXbis8yg5yc5ac22zg26S3fcGaz//LXhG+pApHz/Bt6x7SYeAeZqm9Bpc1dNAOlCRXd/88Q9405s8q1cfqQzM+gU2Dk=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>';

$xml = new DOMDocument();
$xml->loadXML($publickey);

$modulus = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Modulus')->item(0)->nodeValue), 256);
$exponent = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Exponent')->item(0)->nodeValue), 256);

$rsa = new Crypt_RSA();
$rsa->setEncryptionMode(CRYPT_RSA_ENCRYPTION_PKCS1);
$rsa->modulus = $modulus;
$rsa->exponent = $exponent;
$rsa->publicExponent = $exponent;
$rsa->k = strlen($rsa->modulus->toBytes());

$privatekey = '<RSAKeyValue><Modulus>2xrDz/SAJ9QX4qtgnN2E8UlUa5ayPFVhzlv5afeHRL4RDsoqxSDCfL+oZxnZCWAMBNwHeFxcaibhfgG3oXbis8yg5yc5ac22zg26S3fcGaz//LXhG+pApHz/Bt6x7SYeAeZqm9Bpc1dNAOlCRXd/88Q9405s8q1cfqQzM+gU2Dk=</Modulus><Exponent>AQAB</Exponent><P>787qpkCapSXhyqks50GHIlnyWL2QGcPHtOhWBmLiOYod1EjrYKM7w5AMN251b+Q/hv4Injbc3LbZzCo49J/75Q==</P><Q>6eX8GJx/9vv8LHwqQEVrYTcAl2uP+4dUkQCCNWTvJoAY2W3LuG8oPbqPzoDLlj/9581xgnI57jkV1g7g/2HtxQ==</Q><DP>Xe0YgReKuqaUwnDysn069ZxvTIyq1TyWiuf5UbUHUGwldNE+x/IHZXiVIFz2SGYI79GuBHIOnbBMrCfZeQ70dQ==</DP><DQ>eyD66OnZ42cbhT+H7nWc5XxS72NMVJkVR5AA+6K60oW0jyFhkSHTCUvg0FC028+sFg7spkMDhAjBGgKTJ12iEQ==</DQ><InverseQ>50MjKmCl9DZjequHmfW3PZ0cwcTLjhakx1qTcl/Xur0SzgdsIW3ncKJVbG7vfpRlHfpH2uNGL7lR66NAj/qI+A==</InverseQ><D>RiTibU/0O0v+PZXp/y434ls8iJkdBI29Gyh8x7zz9ED5CwgT+zoKqY9eJWuz/Plfv6qFRbYj6+P4qrN4C1wZJSkE/vhqHPxdlyNTmoehS0FLiBBhX2EFHg+srU+ArVWTfqrvhJhhacp6R7wzFqgH2W6vixaYrmtln77dR7PI39E=</D></RSAKeyValue>';

$xml = new DOMDocument();
$xml->loadXML($privatekey);

$d = new Math_BigInteger(base64_decode($xml->getElementsByTagName('D')->item(0)->nodeValue), 256);
$dp = new Math_BigInteger(base64_decode($xml->getElementsByTagName('DP')->item(0)->nodeValue), 256);
$dq = new Math_BigInteger(base64_decode($xml->getElementsByTagName('DQ')->item(0)->nodeValue), 256);
$inverseq = new Math_BigInteger(base64_decode($xml->getElementsByTagName('InverseQ')->item(0)->nodeValue), 256);
$p = new Math_BigInteger(base64_decode($xml->getElementsByTagName('P')->item(0)->nodeValue), 256);
$q = new Math_BigInteger(base64_decode($xml->getElementsByTagName('Q')->item(0)->nodeValue), 256);

$rsa->exponents = array(1=> $dp, $dq);
$rsa->coefficients = array(2 => $inverseq);
$rsa->primes = array(1 => $p, $q);

$ciphertext = base64_decode('esYXv4ZezAO2k8d6G2ZSwxjvnQcyYpTfBEPcBWUGy7jNJYLvWEfu/aFGB+aPl2jVPVDQCScRTJbpxTYFn/fWq4EeI7Hsly9c6zH/C4+FQbtmw1BTVg9u5DNw31GY/q22eVveHtjgY+An0uG2eLj/jRS2zk5enWkYMrcA/QxobaI=');
$ciphertext = new Math_BigInteger($ciphertext, 256);
echo $rsa->_exponentiate($ciphertext)->toBytes();

Per that the plaintext isn't Data("test") or "test" or whatever but "123". Is that correct?
TerraFrost
Legendary Guard
 
Posts: 12357
Joined: Wed Dec 04, 2002 6:37 am

Next

Return to phpseclib support

Who is online

Users browsing this forum: No registered users and 2 guests