RSA512
RSA512
This class represents a private key for the asymmetric encryption engine.
Note: This class uses OpenSSL for strong encryption
generate(integer $keyLength = self::RSA4096) : string
Create a random private key of the given length (in bits).
You can use predefined constants to have valid keylength values.
The higher the key length, the higher the security the higher the required time to generate the key.
Usage example:
//give a name to the file containing the generation result
$filename = APPLICATION_DIR."newkey.private.pem";
//generate the new key $serailized_key = PrivateKey::generate(PrivateKey::RSA4096);
//export to file the serialized key file_put_contents($filename, $serailized_key); //NOTE: this example is really BAD because the file is NOT encrypted
//yes, you can load private keys directly from file $private_key = new PrivateKey("file://".$filename);
integer | $keyLength | the length (in bits) of the private key to e generated |
the given key length is not an integer power of two
the error occurred while generating and exporting the new private key
the serialized private key
__construct(string $customKey, string $customKeyPassword = '')
Used to create a private key from the given serialized key.
string | $customKey | the private key serialized as a string |
string | $customKeyPassword | the password to decrypt the serialized private key (if necessary) |
the given key and/or password isn't a valid string
the given key is invalid
export(string $keyPassword = '') : string
Export this private key in a string format.
The resulting string can be used to construct another PrivateKey instance:
use Gishiki\Security\Encryption\Asymmetric\PrivateKey;
//this is the exported private key $exported_key = "...";
//rebuild the private key $privateKey = new PrivateKey($exported_key);
string | $keyPassword | the private key password |
the given password is not a string
the given key is invalid
the serialized private key