Esempio n. 1
0
 public function encrypt($data)
 {
     $mcrypt_ext = new \Bitpay\Crypto\McryptExtension();
     $fingerprint = sha1(sha1(LC_DIR_MODULES . 'BitPay' . LC_DS . 'BitPay' . LC_DS . 'lib' . LC_DS));
     $fingerprint = substr($fingerprint, 0, 24);
     return $mcrypt_ext->encrypt($data, $fingerprint, '00000000');
 }
 function bitpay_encrypt($data)
 {
     if (false === isset($data) || true === empty($data)) {
         throw new \Exception('The Bitpay payment plugin was called to encrypt data but no data was passed!');
     }
     $mcrypt_ext = new \Bitpay\Crypto\McryptExtension();
     $fingerprint = sha1(sha1(__DIR__));
     if (true === isset($fingerprint) && true === isset($mcrypt_ext) && strlen($fingerprint) > 24) {
         $fingerprint = substr($fingerprint, 0, 24);
         if (false === isset($fingerprint) || true === empty($fingerprint)) {
             throw new \Exception('The Bitpay payment plugin was called to encrypt data but could not generate a fingerprint parameter!');
         }
         $encrypted = $mcrypt_ext->encrypt(base64_encode(serialize($data)), $fingerprint, '00000000');
         if (true === empty($encrypted)) {
             throw new \Exception('The Bitpay payment plugin was called to serialize an encrypted object and failed!');
         }
         return $encrypted;
     } else {
         wp_die('Invalid server fingerprint generated');
     }
 }
function save_keys($token, $network, $private, $public, $sin)
{
    // Access to Wordpress Database
    global $wpdb;
    try {
        $table_name = $wpdb->prefix . 'bitpay_keys';
        //Get Current user's ids
        $user_ID = get_current_user_id();
        //Get Token's facade
        $facade = $token->getFacade();
        //Token's with POS facade are seen by all admin by default
        $enable_all = $facade === 'pos' ? 'true' : 'false';
        //Protect your data!
        $mcrypt_ext = new \Bitpay\Crypto\McryptExtension();
        $fingerprint = sha1(sha1(__DIR__));
        $fingerprint = substr($fingerprint, 0, 24);
        //Make sure a token is set to in_use=='true' if one is not already in use
        $tokens_in_use = $wpdb->get_var("SELECT COUNT(*) FROM {$table_name} WHERE `facade` = '{$facade}' AND `in_use` = 'true'");
        $in_use = $tokens_in_use > 0 ? 'false' : 'true';
        //Setting values for database
        $data = array('private_key' => $mcrypt_ext->encrypt(base64_encode(serialize($private)), $fingerprint, '00000000'), 'public_key' => $mcrypt_ext->encrypt(base64_encode(serialize($public)), $fingerprint, '00000000'), 'sin' => $sin, 'token' => $mcrypt_ext->encrypt(base64_encode(serialize($token)), $fingerprint, '00000000'), 'network' => $network, 'facade' => $facade, 'user_id' => $user_ID, 'enable_all' => $enable_all, 'in_use' => $in_use, 'paired' => "true", 'created_at' => current_time('mysql'));
        //Check for update or post
        $wpdb->insert($table_name, $data);
    } catch (\Exception $e) {
        debuglog('[Error] In Bitpay plugin, save_keys() function on line ' . $e->getLine() . ', with the error "' . $e->getMessage() . '" .');
        throw $e;
    }
}