public generateNewKeypair ( boolean $usedForPasswords = false ) : string | ||
$usedForPasswords | boolean | TRUE if this keypair should be used to encrypt passwords (then decryption won't be allowed!). |
return | string | The RSA public key fingerprint for reference |
public function generateNewKeypair($usedForPasswords = false)
{
$keyResource = openssl_pkey_new($this->openSSLConfiguration);
if ($keyResource === false) {
throw new SecurityException('OpenSSL private key generation failed.', 1254838154);
}
$modulus = $this->getModulus($keyResource);
$privateKeyString = $this->getPrivateKeyString($keyResource);
$publicKeyString = $this->getPublicKeyString($keyResource);
$privateKey = new OpenSslRsaKey($modulus, $privateKeyString);
$publicKey = new OpenSslRsaKey($modulus, $publicKeyString);
return $this->storeKeyPair($publicKey, $privateKey, $usedForPasswords);
}
/** * @test */ public function shutdownDoesNotSavesKeysToKeystoreFileIfKeysWereNotModified() { $this->assertFalse(file_exists('vfs://Foo/EncryptionKey')); $keyPairUuid = $this->rsaWalletService->generateNewKeypair(true); $this->rsaWalletService->shutdownObject(); $this->assertTrue(file_exists('vfs://Foo/EncryptionKey')); $this->rsaWalletService->initializeObject(); $this->rsaWalletService->getPublicKey($keyPairUuid); // Hack: remove the file so we can actually detect if shutdown() would write it: unlink('vfs://Foo/EncryptionKey'); $this->rsaWalletService->shutdownObject(); $this->assertFalse(file_exists('vfs://Foo/EncryptionKey')); }