You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.3 KiB
59 lines
1.3 KiB
<?php
|
|
|
|
function setupPrivKey($privKey)
|
|
{
|
|
if (is_resource($privKey))
|
|
{
|
|
return true;
|
|
}
|
|
$pem = chunk_split($privKey, 64, "\n");
|
|
$pem = "-----BEGIN RSA PRIVATE KEY-----\n" . $pem . "-----END RSA PRIVATE KEY-----\n";
|
|
// $privKey = openssl_pkey_get_private($pem);
|
|
$file = fopen("online_private_key.pem","w");
|
|
if ($file){
|
|
fwrite($file,$pem);
|
|
fclose($file);
|
|
echo "write successfully!\n";
|
|
}else {
|
|
echo "open file error!\n";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* * setup the public key
|
|
*/
|
|
function setupPubKey($pubKey)
|
|
{
|
|
if (is_resource($pubKey))
|
|
{
|
|
return true;
|
|
}
|
|
$pem = chunk_split($pubKey, 64, "\n");
|
|
$pem = "-----BEGIN PUBLIC KEY-----\n" . $pem . "-----END PUBLIC KEY-----\n";
|
|
// $pubKey = openssl_pkey_get_public($pem);
|
|
$file = fopen("online_public_key.pem","w");
|
|
if ($file){
|
|
fwrite($file,$pem);
|
|
fclose($file);
|
|
echo "write successfully!\n";
|
|
}else {
|
|
echo "open file error!\n";
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
$public_key = file_get_contents("public_key.pem");
|
|
$private_key = file_get_contents("private_key.pem");
|
|
|
|
// echo $public_key;
|
|
// echo $private_key;
|
|
|
|
$public_key = setupPubKey($public_key);
|
|
$private_key = setupPrivKey($private_key);
|
|
echo $public_key;
|
|
echo $private_key;
|
|
|
|
?>
|
|
|