X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fcrypto.php;h=6fc9a287e4238ca5743c35920fab1d2c48afc91d;hb=6e06d415bb1fa085515937229b167fc59acfc194;hp=0feb45c2474b58edbb0f27e066d7c382eaf2e992;hpb=c3139fa0fd49b0b4de4568d46a6946c75ccb2a62;p=friendica.git diff --git a/include/crypto.php b/include/crypto.php index 0feb45c247..6fc9a287e4 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -292,4 +292,38 @@ function zot_unencapsulate($data,$prvkey) { $ret['sender'] = $s; $ret['data'] = aes_unencapsulate($x,$prvkey); return $ret; -} \ No newline at end of file +} + +function new_keypair($bits) { + + $openssl_options = array( + 'digest_alg' => 'sha1', + 'private_key_bits' => $bits, + 'encrypt_key' => false + ); + + $conf = get_config('system','openssl_conf_file'); + if($conf) + $openssl_options['config'] = $conf; + + $result = openssl_pkey_new($openssl_options); + + if(empty($result)) { + logger('new_keypair: failed'); + return false; + } + + // Get private key + + $response = array('prvkey' => '', 'pubkey' => ''); + + openssl_pkey_export($result, $response['prvkey']); + + // Get public key + $pkey = openssl_pkey_get_details($result); + $response['pubkey'] = $pkey["key"]; + + return $response; + +} +