Created
September 9, 2015 14:11
-
-
Save niraj-shah/81877fcf5eca02b08f50 to your computer and use it in GitHub Desktop.
Create Private and Public Keys using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$config = array( | |
"digest_alg" => "sha512", | |
"private_key_bits" => 4096, | |
"private_key_type" => OPENSSL_KEYTYPE_RSA, | |
); | |
// Create the private and public key | |
$result = openssl_pkey_new( $config ); | |
// Extract the private key from $result to $privKey | |
openssl_pkey_export( $result, $privKey ); | |
// Extract the public key from $result to $pubKey | |
$pubKey = openssl_pkey_get_details( $result ); | |
$pubKey = $pubKey["key"]; | |
// save private key to file | |
file_put_contents( 'private.key', $privKey ); | |
// save public key to file | |
file_put_contents( 'public.pub', $pubKey ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment