diff --git a/phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php b/phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php index 30acd328..4c93b873 100644 --- a/phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php +++ b/phpseclib/Crypt/RSA/Formats/Keys/PuTTY.php @@ -125,6 +125,6 @@ abstract class PuTTY extends Progenitor */ public static function savePublicKey(BigInteger $n, BigInteger $e) { - return self::wrapPublicKey(Strings::packSSH2($e, $n), 'ssh-rsa'); + return self::wrapPublicKey(Strings::packSSH2('ii', $e, $n), 'ssh-rsa'); } } diff --git a/tests/Unit/Crypt/RSA/LoadKeyTest.php b/tests/Unit/Crypt/RSA/LoadKeyTest.php index 4c3c3449..9c9173d4 100644 --- a/tests/Unit/Crypt/RSA/LoadKeyTest.php +++ b/tests/Unit/Crypt/RSA/LoadKeyTest.php @@ -980,4 +980,18 @@ Vyaqr/WTPzxdXJAAAADHJvb3RAdmFncmFudAECAwQFBg== $this->assertTrue($key->verify('zzz', $sig)); } + + public function testPuTTYPublic() + { + $orig = '---- BEGIN SSH2 PUBLIC KEY ---- +Comment: "phpseclib-generated-key" +AAAAB3NzaC1yc2EAAAADAQABAAAAQQCo9+BpMRYQ/dL3DS2CyJxRF+j6ctbT3/Qp +84+KeFhnii7NT7fELilKUSnxS30WAvQCCo2yU1orfgqr41mM70MB +---- END SSH2 PUBLIC KEY ----'; + + $orig = preg_replace('#(?assertSame($orig, $key->toString('PuTTY')); + } }