From c26dede97f626b52b7bf8962ed55d1dbda86abe8 Mon Sep 17 00:00:00 2001 From: Hilmar R Date: Sun, 28 Feb 2021 21:06:16 +0100 Subject: get dev --- tests/unit/Lib/KeyutilsTest.php | 93 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 tests/unit/Lib/KeyutilsTest.php (limited to 'tests/unit/Lib') diff --git a/tests/unit/Lib/KeyutilsTest.php b/tests/unit/Lib/KeyutilsTest.php new file mode 100644 index 000000000..d1b0b5ab8 --- /dev/null +++ b/tests/unit/Lib/KeyutilsTest.php @@ -0,0 +1,93 @@ +getPubPKCS8(), $m, $e); + $gen_key = Keyutils::meToPem($m, $e); + self::assertEquals($this->getPubPKCS8(), $gen_key); + } + + public function testRsaToPem() { + $rsa = new RSA(); + $rsa->setPublicKey($this->getPubPKCS8()); + $key = $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1); + $gen_key = Keyutils::rsaToPem($key); + self::assertEquals($gen_key, $this->getPubPKCS8()); + } + + public function testPemToRsa() { + $rsa = new RSA(); + $rsa->setPublicKey($this->getPubPKCS1()); + $key = $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8); + $gen_key = Keyutils::pemToRsa($key); + self::assertEquals($gen_key, $this->getPubPKCS1()); + } + + public function testPemToMe() { + Keyutils::pemToMe($this->getPubPKCS8(), $m, $e); + $gen_key = new RSA(); + $gen_key->loadKey([ + 'e' => new BigInteger($e, 256), + 'n' => new BigInteger($m, 256) + ]); + self::assertEquals($gen_key->getPublicKey(), $this->getPubPKCS8()); + } + +} -- cgit v1.2.3