protected function generatePrivateKey()
 {
     $generator = new KeyGenerator();
     $generator->setType(OPENSSL_KEYTYPE_RSA);
     $generator->setBits(4096);
     $generator->setDigestAlgorithm('SHA1');
     return $generator->generate();
 }
Beispiel #2
0
 public function testGenerate()
 {
     $generator = new KeyGenerator();
     $privateKey = $generator->generate();
     $this->assertContains('PRIVATE KEY', (string) $privateKey);
     $this->assertNotContains('PUBLIC KEY', (string) $privateKey);
     $this->assertContains('PUBLIC KEY', (string) $privateKey->getPublicKey());
     $this->assertNotContains('PRIVATE KEY', (string) $privateKey->getPublicKey());
 }
Beispiel #3
0
 public function testEncryptAndDecrypt()
 {
     $generator = new KeyGenerator();
     $privateKey = $generator->generate();
     $publicKey = $privateKey->getPublicKey();
     $encrypted = $privateKey->encrypt('foobar');
     $this->assertNotSame('foobar', $encrypted);
     $decrypted = $publicKey->decrypt($encrypted);
     $this->assertSame('foobar', $decrypted);
 }