public registerKeyPairFromPrivateKeyString ( string $privateKeyString, boolean $usedForPasswords = false ) : string | ||
$privateKeyString | string | The private key in its string representation |
$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 registerKeyPairFromPrivateKeyString($privateKeyString, $usedForPasswords = false)
{
$keyResource = openssl_pkey_get_private($privateKeyString);
$modulus = $this->getModulus($keyResource);
$publicKeyString = $this->getPublicKeyString($keyResource);
$privateKey = new OpenSslRsaKey($modulus, $privateKeyString);
$publicKey = new OpenSslRsaKey($modulus, $publicKeyString);
return $this->storeKeyPair($publicKey, $privateKey, $usedForPasswords);
}
/** * Import a private key * * Read a PEM formatted private key from stdin and import it into the * RSAWalletService. The public key will be automatically extracted and stored * together with the private key as a key pair. * * You can generate the same fingerprint returned from this using these commands: * * ssh-keygen -yf my-key.pem > my-key.pub * ssh-keygen -lf my-key.pub * * To create a private key to import using this method, you can use: * * ssh-keygen -t rsa -f my-key * ./flow security:importprivatekey < my-key * * Again, the fingerprint can also be generated using: * * ssh-keygen -lf my-key.pub * * @param boolean $usedForPasswords If the private key should be used for passwords * @return void * @see neos.flow:security:importpublickey * @see neos.flow:security:generatekeypair */ public function importPrivateKeyCommand($usedForPasswords = false) { $keyData = ''; // no file_get_contents here because it does not work on php://stdin $fp = fopen('php://stdin', 'rb'); while (!feof($fp)) { $keyData .= fgets($fp, 4096); } fclose($fp); $fingerprint = $this->rsaWalletService->registerKeyPairFromPrivateKeyString($keyData, $usedForPasswords); $this->outputLine('The keypair has been successfully imported. Use the following fingerprint to refer to it in the RSAWalletService: ' . PHP_EOL . PHP_EOL . $fingerprint . PHP_EOL); }