diff --git a/phpseclib/Crypt/Random.php b/phpseclib/Crypt/Random.php index 5e412e8f..6bf61468 100644 --- a/phpseclib/Crypt/Random.php +++ b/phpseclib/Crypt/Random.php @@ -160,8 +160,8 @@ class Random throw new \RuntimeException(__CLASS__ . ' requires at least one symmetric cipher be loaded'); } - $crypto->setKey($key); - $crypto->setIV($iv); + $crypto->setKey(substr($key, 0, $crypto->getKeyLength() >> 3)); + $crypto->setIV(substr($iv, 0, $crypto->getBlockLength() >> 3)); $crypto->enableContinuousBuffer(); } @@ -193,7 +193,7 @@ class Random * @param mixed $arr * @access public */ - function safe_serialize(&$arr) + static function safe_serialize(&$arr) { if (is_object($arr)) { return ''; diff --git a/tests/Unit/Crypt/RSA/ModeTest.php b/tests/Unit/Crypt/RSA/ModeTest.php index 94fb6065..b9d64dff 100644 --- a/tests/Unit/Crypt/RSA/ModeTest.php +++ b/tests/Unit/Crypt/RSA/ModeTest.php @@ -66,7 +66,6 @@ p0GbMJDyR4e9T04ZZwIDAQAB $this->assertTrue($rsa->verify('zzzz', $sig)); } -<<<<<<< HEAD /** * @expectedException \OutOfBoundsException */ @@ -122,13 +121,15 @@ U9VQQSQzY1oZMVX8i1m5WUTLPz2yLJIBQVdXqhMCQBGoiuSoSjafUhV7i1cEGpb88h5NBYZzWXGZ -----END RSA PRIVATE KEY-----'; $rsa->load($privatekey); $rsa->setSaltLength(0); + $rsa->setHash('sha1'); + $rsa->setMGFHash('sha1'); // Check we generate the correct signature. $sig = pack('H*', '0ddfc93548e21d015c0a289a640b3b79aecfdfae045f583c5925b91cc5c399bba181616ad6ae20d9662d966f0eb2fddb550f4733268e34d640f4c9dadcaf25b3c82c42130a5081c6ebad7883331c65b25b6a37ffa7c4233a468dae56180787e2718ed87c48d8d50b72f5850e4a40963b4f36710be250ecef6fe0bb91249261a3'); $this->assertEquals($sig, $rsa->sign($plaintext)); // Check we can verify the signature correctly. - $rsa->loadKey($rsa->getPublicKey()); + $rsa->load($rsa->getPublicKey()); $this->assertTrue($rsa->verify($plaintext, $sig)); } }