X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fcrypto.php;h=ed0a35704e8a5c8f97ab7f26038828fd5b2fd53b;hb=ad5a47aecfe843199c50fb394cca6a77d5c12f3d;hp=88e05b9eb0e34a75a2a2eff9beadfe866cf8c364;hpb=030dcbd467d5faf01e6f62b9cd9b1be6f8974dcc;p=friendica.git diff --git a/include/crypto.php b/include/crypto.php index 88e05b9eb0..ed0a35704e 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -261,32 +261,36 @@ function aes_unencapsulate($data,$prvkey) { return AES256CBC_decrypt(base64url_decode($data['data']),$k,$i); } +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"]; -function zot_encapsulate($data,$sender,$pubkey) { -$res = aes_encapsulate($data,$pubkey); -openssl_public_encrypt($sender,$s,$pubkey); -$s1 = base64url_encode($s,true); - -return <<< EOT - - - {$res['key']} - {$res['iv']} - $s1 - AES-256-CBC - {$res['data']} - -EOT; + return $response; } -function zot_unencapsulate($data,$prvkey) { - $ret = array(); - $c = array(); - $x = parse_xml_string($data); - $c = array('key' => $x->key,'iv' => $x->iv,'data' => $x->data); - openssl_private_decrypt(base64url_decode($x->sender),$s,$prvkey); - $ret['sender'] = $s; - $ret['data'] = aes_unencapsulate($x,$prvkey); - return $ret; -} \ No newline at end of file