1
0
mirror of https://github.com/danog/phpseclib.git synced 2024-11-27 04:46:26 +01:00

RSA: backport macdabby's changes

This commit is contained in:
terrafrost 2016-04-03 21:34:11 -05:00
parent cb2ccea219
commit ac97ce5d69
2 changed files with 36 additions and 2 deletions

View File

@ -1786,7 +1786,7 @@ class Crypt_RSA
function setPrivateKey($key = false, $type = false) function setPrivateKey($key = false, $type = false)
{ {
if ($key === false && !empty($this->publicExponent)) { if ($key === false && !empty($this->publicExponent)) {
unset($this->publicExponent); $this->publicExponent = false;
return true; return true;
} }
@ -1794,7 +1794,7 @@ class Crypt_RSA
if (!$rsa->loadKey($key, $type)) { if (!$rsa->loadKey($key, $type)) {
return false; return false;
} }
unset($rsa->publicExponent); $rsa->publicExponent = false;
// don't overwrite the old key if the new key is invalid // don't overwrite the old key if the new key is invalid
$this->loadKey($rsa); $this->loadKey($rsa);

View File

@ -345,4 +345,38 @@ Z2sKniRCcDT1ZP4=
$this->assertTrue($result); $this->assertTrue($result);
} }
/**
* @group github960
*/
public function testSetLoad()
{
$key = 'PuTTY-User-Key-File-2: ssh-rsa
Encryption: aes256-cbc
Comment: phpseclib-generated-key
Public-Lines: 4
AAAAB3NzaC1yc2EAAAADAQABAAAAgQCqGKukO1De7zhZj6+H0qtjTkVxwTCpvKe4
eCZ0FPqri0cb2JZfXJ/DgYSF6vUpwmJG8wVQZKjeGcjDOL5UlsuusFncCzWBQ7RK
NUSesmQRMSGkVb1/3j+skZ6UtW+5u09lHNsj6tQ51s1SPrCBkedbNf0Tp0GbMJDy
R4e9T04ZZw==
Private-Lines: 8
llx04QMegql0/nE5RvcJSrGrodxt6ytuv/JX2caeZBUyQwQc2WBNYagLHyHPM9jI
9OUWz59FLhjFXZMDNMoUXxVmjwQpOAaVPYNxxFM9AF6/NXFji64K7huD9n4A+kLn
sHwMLWPR5a/tZA0r05DZNz9ULA3mQu7Hz4EQ8ifu3uTPJuTmL51x6RmudYKysb20
fM8VzC3ukvzzRh0pujUVTr/yQdmciASVFnZlt4xQy+ZEOVUAOfwjd//AFfXTvk6x
7A45rNlU/uicHwLgoY1APvRHCFxw7F+uVW5L4mSX7NNzqBKkZ+1qpQTAfQvIfEIb
444+CXsgIyOpqt6VxJH2u6elAtE1wau3YaFR8Alm8m97rFYzRi3oDP5NZYkTCWSV
EOpSeghXSs7IilJu8I6/sB1w5dakdeBSFkIynrlFXkO0uUw+QJJWjxY8SypzgIuP
DzduF6XsQrCyo6dnIpGQCQ==
Private-MAC: 35134b7434bf828b21404099861d455e660e8740';
$rsa = new Crypt_RSA();
$rsa->setPrivateKey($key);
$rsa->loadKey($key);
$rsa = new Crypt_RSA();
$rsa->loadKey($key);
$rsa->setPrivateKey();
$rsa->loadKey($rsa);
}
} }