Esempio n. 1
0
 public function decrypt($string, $encryption_key = null)
 {
     $string = (string) $string;
     $encryption_key = $encryption_key === null ? $this->key : (string) $encryption_key;
     $old_key_size = GibberishAES::size();
     GibberishAES::size(256);
     $result = GibberishAES::dec($string, $encryption_key);
     GibberishAES::size($old_key_size);
     return $result;
 }
 public function testEncryptionWith256BitKeySize()
 {
     GibberishAES::size(256);
     foreach ($this->examples as $example) {
         $encrypted = GibberishAES::enc($example, $this->passPhrase);
         $this->assertEquals($example, GibberishAES::dec($encrypted, $this->passPhrase));
     }
     GibberishAES::size("256");
     foreach ($this->examples as $example) {
         $encrypted = GibberishAES::enc($example, $this->passPhrase);
         $this->assertEquals($example, GibberishAES::dec($encrypted, $this->passPhrase));
     }
 }
 public function ajax_decryption_test()
 {
     $this->output->set_header('Content-Type: application/json; charset=utf-8', true);
     $pass = $this->pass;
     $encrypted_secret_string_256 = $this->input->post('encrypted_secret_string_256');
     $encrypted_secret_string_192 = $this->input->post('encrypted_secret_string_192');
     $encrypted_secret_string_128 = $this->input->post('encrypted_secret_string_128');
     $old_key_size = GibberishAES::size();
     GibberishAES::size(256);
     $decrypted_secret_string_256 = GibberishAES::dec($encrypted_secret_string_256, $pass);
     GibberishAES::size(192);
     $decrypted_secret_string_192 = GibberishAES::dec($encrypted_secret_string_192, $pass);
     GibberishAES::size(128);
     $decrypted_secret_string_128 = GibberishAES::dec($encrypted_secret_string_128, $pass);
     GibberishAES::size($old_key_size);
     $this->output->set_output(json_encode(compact('decrypted_secret_string_256', 'decrypted_secret_string_192', 'decrypted_secret_string_128')));
 }
Esempio n. 4
0
         // Prepare tree
         if ($idTree != $elem['id_tree']) {
             $arbo = $tree->getPath($elem['id_tree'], true);
             foreach ($arbo as $folder) {
                 $arboHtml_tmp = htmlspecialchars(stripslashes($folder->title), ENT_QUOTES);
                 if (empty($arboHtml)) {
                     $arboHtml = $arboHtml_tmp;
                 } else {
                     $arboHtml .= ' » ' . $arboHtml_tmp;
                 }
             }
             fputs($outstream, '
     <tr class="path"><td colspan="5">' . $arboHtml . '</td></tr>');
             $idTree = $elem['id_tree'];
         }
         $encPw = GibberishAES::enc($elem['pw'], $_POST['pdf_password']);
         fputs($outstream, '
     <tr class="' . $lineType . '">
         <td>' . addslashes($elem['label']) . '</td>
         <td align="center"><span class="span_pw" id="span_' . $elem['id'] . '"><a href="#" onclick="decryptme(' . $elem['id'] . ', \'' . $encPw . '\');return false;">Decrypt </a></span><input type="hidden" id="hide_' . $elem['id'] . '" value="' . $encPw . '" /></td>
         <td>' . $desc . '</td>
         <td align="center">' . $login . '</td>
         <td align="center">' . $url . '</td>
         </tr>');
     }
     fclose($outstream);
     // send back and continue
     echo '[{"loop":"true", "number":"' . $_POST['number'] . '", "cpt":"' . $_POST['cpt'] . '", "file":"' . $_POST['file'] . '", "idsList":"' . $_POST['idsList'] . '" , "file_link":"' . $_POST['file_link'] . '"}]';
     break;
     //CASE export in HTML format - Iteration loop
 //CASE export in HTML format - Iteration loop
Esempio n. 5
0
 protected static function mbstring_func_overload()
 {
     if (!isset(self::$mbstring_func_overload)) {
         self::$mbstring_func_overload = extension_loaded('mbstring') && ini_get('mbstring.func_overload');
     }
     return self::$mbstring_func_overload;
 }
Esempio n. 6
0
 protected static function aes_cbc_decrypt($crypted, $key, $iv)
 {
     $key_size = self::$key_size;
     if (!isset(self::$openssl_decrypt_exists)) {
         self::$openssl_decrypt_exists = function_exists('openssl_decrypt') && version_compare(PHP_VERSION, '5.3.3', '>=');
         // We need $iv parameter.
     }
     if (self::$openssl_decrypt_exists) {
         return openssl_decrypt($crypted, "aes-{$key_size}-cbc", $key, true, $iv);
     }
     $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     if (mcrypt_generic_init($cipher, $key, $iv) != -1) {
         $decrypted = mdecrypt_generic($cipher, $crypted);
         mcrypt_generic_deinit($cipher);
         mcrypt_module_close($cipher);
         return self::remove_pkcs7_pad($decrypted);
     }
     return false;
 }
Esempio n. 7
0
        }
        $data00 = $key . $salt;
        $md5_hash = array();
        $md5_hash[0] = md5($data00, true);
        $result = $md5_hash[0];
        for ($i = 1; $i < $rounds; $i++) {
            $md5_hash[$i] = md5($md5_hash[$i - 1] . $data00, true);
            $result .= $md5_hash[$i];
        }
        $key = substr($result, 0, $key_length);
        $iv = substr($result, $key_length, $block_length);
        return openssl_decrypt($encrypted, "aes-" . $this->_nKeySize . "-cbc", $key, true, $iv);
    }
    /**
     * Sets the key-size for encryption/decryption in number of bits
     * @param  $nNewSize int The new key size. The valid integer values are: 128, 192, 256 (default) */
    function setMode($nNewSize)
    {
        if (is_null($nNewSize) || empty($nNewSize) || !is_int($nNewSize) || !in_array($nNewSize, self::$valid_key_sizes)) {
            return;
        }
        $this->_nKeySize = $nNewSize;
    }
}
$q = $_POST["str"];
$q = str_replace(' ', '+', $q);
echo "From Server Received: " . "<br>" . $q;
$encryptor = new \GibberishAES();
$encryptionKey = "abc";
$stringOriginal = $encryptor->decrypt($q, $encryptionKey);
echo "<br> From Server Sent: <br>" . $stringOriginal;
Esempio n. 8
0
 protected static function aes_cbc_decrypt($crypted, $key, $iv)
 {
     $key_size = self::$key_size;
     if (!isset(self::$openssl_decrypt_exists)) {
         self::$openssl_decrypt_exists = function_exists('openssl_decrypt') && version_compare(PHP_VERSION, '5.3.3', '>=');
         // We need $iv parameter.
     }
     if (self::$openssl_decrypt_exists) {
         return openssl_decrypt($crypted, "aes-{$key_size}-cbc", $key, true, $iv);
     }
     if (!isset(self::$mcrypt_exists)) {
         self::$mcrypt_exists = function_exists('mcrypt_encrypt');
     }
     if (self::$mcrypt_exists) {
         $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
         if (mcrypt_generic_init($cipher, $key, $iv) != -1) {
             $decrypted = mdecrypt_generic($cipher, $crypted);
             mcrypt_generic_deinit($cipher);
             mcrypt_module_close($cipher);
             return self::remove_pkcs7_pad($decrypted);
         }
         return false;
     }
     if (!isset(self::$openssl_cli_exists)) {
         self::$openssl_cli_exists = self::openssl_cli_exists();
     }
     if (self::$openssl_cli_exists) {
         $string = base64_encode($crypted);
         $cmd = 'echo ' . self::escapeshellarg($string) . ' | openssl enc -d -a -A -aes-' . $key_size . '-cbc -K ' . self::strtohex($key) . ' -iv ' . self::strtohex($iv);
         exec($cmd, $output, $return);
         if ($return == 0 && isset($output[0])) {
             return $output[0];
         }
         return false;
     }
     trigger_error('GibberishAES: System requirements failure, please, check them.', E_USER_WARNING);
     return false;
 }
Esempio n. 9
0
 function preferences_save($args)
 {
     if ($args['section'] == 'jabber') {
         libgpl::include_php('plugins/libgpl/gibberish/GibberishAES.php');
         $enabled = get_input_value('_jappix_enabled', RCUBE_INPUT_POST);
         $username = trim(get_input_value('_jabber_username', RCUBE_INPUT_POST));
         if (!$username && $enabled) {
             $this->rc->output->show_message('jappix4roundcube.usernameempty', 'error');
             $args['abort'] = true;
         }
         if (preg_match('/[@\\/\\ ]/', $username)) {
             $this->rc->output->show_message('jappix4roundcube.usernameinvalid', 'error');
             $this->rc->output->set_env('jabber_username', $this->rc->config->get('jabber_username', ''));
             $args['abort'] = true;
         } else {
             $args['prefs']['jabber_username'] = $username;
             $this->rc->output->set_env('jabber_username', $args['prefs']['jabber_username']);
         }
         $domain = trim(get_input_value('_jabber_domain', RCUBE_INPUT_POST));
         if (!$this->is_valid_domain_name($domain)) {
             $this->rc->output->show_message('jappix4roundcube.domaininvalid', 'error');
             $this->rc->output->set_env('jabber_domain', $this->rc->config->get('jabber_domain', 'jappix.com'));
             $args['abort'] = true;
         } else {
             $args['prefs']['jabber_domain'] = $domain;
             $this->rc->output->set_env('jabber_domain', $args['prefs']['jabber_domain']);
         }
         $password = trim(get_input_value('_jabber_password', RCUBE_INPUT_POST));
         if (!$password && $this->rc->config->get('jappix_inherit')) {
             $password = $this->rc->decrypt($_SESSION['password']);
         }
         if ($password) {
             $key = md5($this->rc->user->data['username'] . ':' . $this->rc->decrypt($_SESSION['password']));
             $enc = GibberishAES::enc($password, $key);
             $args['prefs']['jabber_enc'] = $enc;
             $this->rc->output->set_env('jabber_enc', $enc);
         }
         $args['prefs']['jappix_enabled'] = $enabled;
         $args['prefs']['jappix_enabled'] = $args['prefs']['jappix_enabled'] ? 1 : 0;
         if ($args['prefs']['jappix_enabled'] == 0) {
             $this->rc->session->remove('jappixminiframe');
         }
         $args['prefs']['jappix_full'] = get_input_value('_jappix_full', RCUBE_INPUT_POST);
         $args['prefs']['jappix_full'] = $args['prefs']['jappix_full'] ? 1 : 0;
         $args['prefs']['jappix_mini'] = get_input_value('_jappix_mini', RCUBE_INPUT_POST);
         $args['prefs']['jappix_mini'] = $args['prefs']['jappix_mini'] ? 1 : 0;
         $args['prefs']['jappix_mini_autologon'] = get_input_value('_jappix_mini_autologon', RCUBE_INPUT_POST);
         $args['prefs']['jappix_mini_autologon'] = $args['prefs']['jappix_mini_autologon'] ? 1 : 0;
         $this->rc->output->set_env('jabber_mini', $args['prefs']['jappix_mini'] ? true : false);
         $this->rc->output->set_env('jabber_autologon', $args['prefs']['jappix_mini_autologon'] ? true : false);
     }
     return $args;
 }
Esempio n. 10
0
 public static function dec($data, $key)
 {
     return GibberishAES::dec($data, $key);
 }