/var/www/html_it/wp-content/plugins/show-link-image/admin/rsa.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php

// Encrypt the data to $encrypted using the public key:
// openssl_public_encrypt($data, $encrypted, $pubKey);
// Decrypt the data using the private key and store the results in $decrypted:
// openssl_private_decrypt($encrypted, $decrypted, $privKey);
// Encrypt the data to $encrypted using the private key:
// openssl_private_encrypt($data, $encrypted, $privKey, OPENSSL_PKCS1_PADDING);
// Decrypt the data using the public key and store the results in $decrypted:
// openssl_public_decrypt($encrypted, $decrypted, $pubKey);

function fifu_create_keys($email) {

    require( 
$_SERVER['DOCUMENT_ROOT'] . '/wp-load.php' );

    
$config = array(
        
"digest_alg" => "sha256",
        
"private_key_bits" => 2048,
        
"private_key_type" => OPENSSL_KEYTYPE_RSA,
    );

    
// Create the private and public key
    
$res openssl_pkey_new($config);

    
// Extract the private key from $res to $privKey
    
openssl_pkey_export($res$privKey);

    
// Extract the public key from $res to $pubKey
    
$pubKey openssl_pkey_get_details($res);
    
$pubKey $pubKey["key"];

    
// Store key
    
update_option('fifu_su_email'base64_encode($email), 'no');
    
update_option('fifu_su_privkey'base64_encode(openssl_encrypt($privKey"AES-128-ECB"$email $_SERVER['SERVER_NAME'])), 'no');

    return 
base64_encode($pubKey);
}

function 
fifu_create_signature($data$time) {
    
// Recover key
    
$email base64_decode(get_option('fifu_su_email'));
    
$privKey openssl_decrypt(base64_decode(get_option('fifu_su_privkey')), "AES-128-ECB"$email $_SERVER['SERVER_NAME']);

    
// $data is assumed to contain the data to be signed
    // fetch private key from file and ready it
    
$pkeyid openssl_pkey_get_private($privKey);

    
// default value
    
if ($data == null)
        
$data $email;

    
// compute signature
    
openssl_sign($data $time$signature$privKeyOPENSSL_ALGO_SHA256);

    
// free the key from memory
    
openssl_free_key($pkeyid);

    return 
base64_encode($signature);
}