private static function _getKey() { if (defined('APPLICATION_ENCRYPTION_KEY') && strlen(APPLICATION_ENCRYPTION_KEY) > 7) { $keyPart1 = substr(APPLICATION_ENCRYPTION_KEY, 0, 8); } else { $keyPart1 = PHP_Crypt::createKey(PHP_Crypt::RAND, 16); $keyPart1 = ''; } if (isset($_COOKIE[Encryption::$_keyName])) { $keyPart2 = $_COOKIE[Encryption::$_keyName]; } else { // Create a new key and store it in the cookie $keyPart2 = PHP_Crypt::createKey(PHP_Crypt::RAND, $keyPart1 ? 8 : 16); // TODO: add cookie settings echo "setting zpek cookie<br>"; setcookie(Encryption::$_keyName, $keyPart2); } return $keyPart1 . $keyPart2; }
function GenerateCryptKey($size) { return PHP_Crypt::createKey(PHP_Crypt::RAND, $size); }
*/ error_reporting(E_ALL | E_STRICT); include dirname(__FILE__) . "/../phpCrypt.php"; use PHP_Crypt\PHP_Crypt; /* * The example below uses Linux/Unix /dev/urandom to create a random * string of bytes. Because AES-128 uses a 128 bit (16 byte) key, we * request 16 bytes in the second parameter. Please read above for the * different constants used to create a key. * * WE CAN USE THE FOLLOWING METHODS OF CREATING AN KEY: * $key = PHP_Crypt::createKey(PHP_Crypt::RAND); // The default, uses PHP's mt_rand() * $key = PHP_Crypt::createKey(PHP_Crypt::RAND_DEV_RAND); // unix only, uses /dev/random * $key = PHP_Crypt::createKey(PHP_Crypt::RAND_DEV_URAND);// unix only, uses /dev/urandom * $key = PHP_Crypt::createKey(PHP_Crypt::RAND_WIN_COM); // Windows only, uses the com_dotnet extension */ $key = PHP_Crypt::createKey(PHP_Crypt::RAND_DEV_URAND, 16); $text = "This is my secret message."; // now create the phpCrypt object and set the cipher to AES-128, with CTR mode $crypt = new PHP_Crypt($key, PHP_Crypt::CIPHER_AES_128, PHP_Crypt::MODE_CTR); $iv = $crypt->createIV(); $encrypt = $crypt->encrypt($text); $crypt->IV($iv); $decrypt = $crypt->decrypt($encrypt); print "CIPHER: " . $crypt->cipherName() . "\n"; print "MODE: " . $crypt->modeName() . "\n"; print "PLAIN TEXT: {$text}\n"; print "PLAIN TEXT HEX: " . bin2hex($text) . "\n"; print "ENCRYPTED HEX: " . bin2hex($encrypt) . "\n"; print "DECRYPTED: {$decrypt}\n"; print "DECRYPTED HEX: " . bin2hex($decrypt) . "\n";
/*if (empty($history)) { $history = date($_SESSION['settings']['date_format']." ".$_SESSION['settings']['time_format'], $record['date'])." - ".$record['login']." - ".$LANG[$record['action']]." - ".(!empty($record['raison']) ? (count($reason) > 1 ? $LANG[trim($reason[0])].' : '.$reason[1] : ($record['action'] == "at_manual" ? $reason[0] : $LANG[trim($reason[0])])):''); } else { $history .= "<br />".date($_SESSION['settings']['date_format']." ".$_SESSION['settings']['time_format'], $record['date'])." - ".$record['login']." - ".$LANG[$record['action']]." - ".(!empty($record['raison']) ? (count($reason) > 1 ? $LANG[trim($reason[0])].' => '.$reason[1] : ($record['action'] == "at_manual" ? $reason[0] : $LANG[trim($reason[0])])):''); }*/ if (trim($reason[0]) == "at_pw") { if (empty($historyOfPws)) { $historyOfPws = $LANG['previous_pw'] . "\n" . $reason[1]; } else { $historyOfPws .= "\n" . $reason[1]; } } } } // generate 2d key $_SESSION['key_tmp'] = bin2hex(PHP_Crypt::createKey(PHP_Crypt::RAND, 16)); // Prepare files listing $files = $filesEdit = ""; // launch query $rows = DB::query("SELECT id, name, file, extension FROM " . prefix_table("files") . " WHERE id_item=%i", $_POST['id']); foreach ($rows as $record) { // get icon image depending on file format $iconImage = fileFormatImage($record['extension']); // prepare text to display if (strlen($record['name']) > 60 && strrpos($record['name'], ".") >= 56) { $filename = substr($record['name'], 0, 50) . "(truncated)" . substr($record['name'], strrpos($record['name'], ".")); } else { $filename = $record['name']; } // If file is an image, then prepare lightbox. If not image, then prepare donwload if (in_array($record['extension'], $k['image_file_ext'])) {