assertNotNull($cipher); $this->assertEquals('', $cipher->getMatDesc()); $this->assertEquals('RSA/NONE/PKCS1Padding', $cipher->getWrapAlgorithm()); $cipher = new MasterRsaCipher(self::RSA_PUBLIC_KEY, self::RSA_PRIVATE_KEY, ['key' => 'value']); $this->assertNotNull($cipher); $this->assertEquals('{"key":"value"}', $cipher->getMatDesc()); $this->assertEquals('RSA/NONE/PKCS1Padding', $cipher->getWrapAlgorithm()); $data = 'hello world'; $edata = $cipher->encrypt($data); $this->assertNotEquals($data, $edata); $eedata = $cipher->decrypt($edata); $this->assertEquals($data, $eedata); } public function testFail() { try { $cipher = new MasterRsaCipher('RSA_PUBLIC_KEY', self::RSA_PRIVATE_KEY, ['key' => 'value']); $this->assertTrue(false, 'should not here'); } catch (\Exception $e) { $this->assertStringContainsString('RSA key format is not supported', $e->getMessage()); } try { $cipher = new MasterRsaCipher(self::RSA_PUBLIC_KEY, 'RSA_PRIVATE_KEY', ['key' => 'value']); $this->assertTrue(false, 'should not here'); } catch (\Exception $e) { $this->assertStringContainsString('RSA key format is not supported', $e->getMessage()); } try { $cipher = new MasterRsaCipher(null, null, null); $cipher->encrypt('hello world 123'); $this->assertTrue(false, 'should not here'); } catch (\Exception $e) { $this->assertStringContainsString('RSA public key is none or invalid', $e->getMessage()); } try { $cipher = new MasterRsaCipher(null, null, null); $cipher->decrypt('hello world 123'); $this->assertTrue(false, 'should not here'); } catch (\Exception $e) { $this->assertStringContainsString('RSA private key is none or invalid', $e->getMessage()); } } }