]> git.mxchange.org Git - friendica.git/blobdiff - include/crypto.php
Typo in notifier.
[friendica.git] / include / crypto.php
index 0feb45c2474b58edbb0f27e066d7c382eaf2e992..ed0a35704e8a5c8f97ab7f26038828fd5b2fd53b 100644 (file)
@@ -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
-<?xml version='1.0' encoding='UTF-8'?>
-<zot:msg xmlns:zot='http://purl.org/zot/1.0'>
- <zot:key>{$res['key']}</zot:key>
- <zot:iv>{$res['iv']}</zot:iv>
- <zot:env>$s1</zot:env>
- <zot:sig key_id="$keyid">$sig</zot:sig>
- <zot:alg>AES-256-CBC</zot:alg>
- <zot:data type='application/magic-envelope+xml'>{$res['data']}</zot:data>
-</zot:msg>
-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