X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fcrypto.php;h=ed0a35704e8a5c8f97ab7f26038828fd5b2fd53b;hb=159a7bda85d1514ed3a8d67cea7deca6ed96b437;hp=0feb45c2474b58edbb0f27e066d7c382eaf2e992;hpb=8a80ea24d1d8039be6dc532c9db23c60e71eb467;p=friendica.git diff --git a/include/crypto.php b/include/crypto.php index 0feb45c247..ed0a35704e 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -261,35 +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' => ''); -// This has been superceded. + openssl_pkey_export($result, $response['prvkey']); -function zot_encapsulate($data,$envelope,$pubkey) { -$res = aes_encapsulate($data,$pubkey); + // Get public key + $pkey = openssl_pkey_get_details($result); + $response['pubkey'] = $pkey["key"]; -return <<< EOT - - - {$res['key']} - {$res['iv']} - $s1 - $sig - AES-256-CBC - {$res['data']} - -EOT; + return $response; } -// so has this - -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