From a485e85ba5b4d549fb8facf21a18053b31249fc8 Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 18 Jan 2020 17:31:10 -0600 Subject: [PATCH 1/2] Tests/RSA: add additional assert for MSBLOBs --- tests/Unit/Crypt/RSA/LoadKeyTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index ac3efd78..4c3c3449 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -440,6 +440,7 @@ Private-MAC: 35134b7434bf828b21404099861d455e660e8740'; $plaintext = 'zzz'; $privKey = PublicKeyLoader::load($key); + $this->assertSame($key, $privKey->toString('MSBLOB')); $this->assertInstanceOf(PrivateKey::class, $privKey); $this->assertSame($privKey->getLoadedFormat(), 'MSBLOB'); $this->assertGreaterThanOrEqual(1, strlen("$privKey")); From 0e1dff2be71ceb2ab60fb9e7b7e474e2f3810b6d Mon Sep 17 00:00:00 2001 From: terrafrost Date: Sat, 18 Jan 2020 17:47:24 -0600 Subject: [PATCH 2/2] RSA: fix MSBLOB encoding error --- phpseclib/Crypt/RSA/Formats/Keys/MSBLOB.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpseclib/Crypt/RSA/Formats/Keys/MSBLOB.php b/phpseclib/Crypt/RSA/Formats/Keys/MSBLOB.php index deb9467b..60dff682 100644 --- a/phpseclib/Crypt/RSA/Formats/Keys/MSBLOB.php +++ b/phpseclib/Crypt/RSA/Formats/Keys/MSBLOB.php @@ -200,7 +200,7 @@ abstract class MSBLOB $key.= strrev($primes[2]->toBytes()); $key.= strrev($exponents[1]->toBytes()); $key.= strrev($exponents[2]->toBytes()); - $key.= strrev($coefficients[1]->toBytes()); + $key.= strrev($coefficients[2]->toBytes()); $key.= strrev($d->toBytes()); return Base64::encode($key);