public function Set($Setting, $Value) { if ($this->encrypted) { $_SESSION[$this->SessionName][$Setting] = Cipher::encrypt($Value); } else { $_SESSION[$this->SessionName][$Setting] = $Value; } }
/** * Called before any output is sent to create an encrypted cookie with the given value. * * @param string $key cookie name * @param mixed $value to save * @param array $config settings * return boolean */ public static function set($name, $value, $config = NULL) { // Use default config settings if needed extract($config ?: static::$settings); // If the cookie is being removed we want it left blank $value = $value ? base64_encode(Cipher::encrypt(json_encode(array(time(), $value)), $key)) : ''; // Save cookie to user agent setcookie($name, $value, $expires, $path, $domain, $secure, $httponly); }
function encrypt(string $key, string $nonce, string $aad, string $plaintext) : string { $cipher = new Cipher(); $context = $cipher->init($key, $nonce); $cipher->aad($context, $aad); $ciphertext = $cipher->encrypt($context, $plaintext); $tag = $cipher->finish($context); return [$ciphertext, $tag]; }
/** * @param string * @return string */ public function encrypt($data) { return $this->impl->encrypt($data); }
/** * AES暗号形式でデータを暗号化する * @param $argValue エンコードする値 * @param $argKey 暗号キー * @param $argIv IV * @return $encrypt 暗号化データ */ public static function encryptAES($argValue, $argKey, $argIV = null, $argPrefix = '', $argSuffix = '') { // パラメータセット // XXX パラメータは定数で可変出来るようにする $params = array('value' => $argValue, 'key' => $argKey, 'iv' => $argIV, 'algorithm' => 'rijndael-128', 'mode' => 'cbc', 'prefix' => $argPrefix, 'suffix' => $argSuffix); // データを暗号化する $encrypt = Cipher::encrypt($params); // エラー処理 if (false === $encrypt || NULL === $encrypt) { return false; } return $encrypt; }
<?php /** * Encryption test */ require 'Cipher.php'; // First init the class by calling the constructor // Pass your personal key to the constructor as a // parameter. $cipher = new Cipher('AvErrySeCretPasSw0rd!1!2!3!'); $text = 'This is the piece of text we are going to encrypt.'; // Now we encrypt the above text // The returned value will be a base64encoded form of your encrypted // string. $encrypted = $cipher->encrypt($text);
<?php /* testing file */ /* move this file to your MediaWiki directory if you're too lazy to re-set this requires */ require_once "PEAR.php"; require_once "Crypt/RSA.php"; require_once "extensions/PageProtection/Cipher.php"; $plaintext = "This is plaintext."; /* create object */ $c = new Cipher(); if ($c->has_error()) { print "Error: " . $c->get_last_error() . "\n"; exit; } /* encrypt message using default cipher */ $encrypted = $c->encrypt($plaintext); if ($c->has_error()) { print "Error: " . $c->get_last_error() . "\n"; exit; } /* get parameters used during encyprion proccess */ $key = $c->mLastKey; $iv = $c->mLastIV; $cipher = $c->mLastCipher; /* decrypt the encrypted message using obtained values */ $result = $c->decrypt($encrypted, $cipher, $key, $iv); if ($c->has_error()) { print "Error: " . $c->get_last_error() . "\n"; exit; } /* display results */
function encrypt_password($str) { $cipher = new Cipher(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB); $key = "achmadmunandar1234567890"; return $cipher->encrypt($str, $key); }
public function installation() { //Check if any other installations exist? if No then the first one shall be called 'default' $files1 = @$this->file_list(APPPATH . 'config/installations', '.php'); $count = count($files1); $default = false; $encryptedtext = ""; if ($count == 0) { //No other Setup Exists $default = true; } if (!$default) { //The default database details need to be passed to the setup script. Using encryption here as it will he a hidden field in the form. $cipher = new Cipher('transferDB@321'); $databaseDetails = array("host" => $this->config->item('database_host'), "database_username" => $this->config->item('database_username'), "database_password" => $this->config->item('database_password')); $encryptedtext = $cipher->encrypt(serialize($databaseDetails)); //Check if multiple installations are allowed. if (!$this->config->item('multiInstall')) { $data['errorMsg'] = "Your Server administrator has disabled Multiple installations on this Server."; $this->load->view('templates/apierror', $data); return; } } //List of languages to be shown. $lang = array("English" => "English", "Spanish" => "Español", "Italian" => "Italiano", "Portuguese" => "Portugués", "German" => "Deutsch", "Dutch" => "Nederlands", "Bulgarian" => "български", "Croatian" => "Hrvatski", "French" => "Français", "Russian" => "Русский", "Tagalog" => "Tagalog", "Czech" => "Český", "Ukranian" => "Українська", "Chinese" => "中文"); $langOptions = genOptions($lang); //Check if any other installations exist? if No then the first one shall be called 'default' $files1 = @$this->file_list(APPPATH . 'config/installations', '.php'); $default = false; if ($count == 0) { //No other Setup Exists $default = true; } $_SESSION['setup'] = true; $data = $this->StyleData; $data['langOptions'] = $langOptions; $data['default'] = $default; $data['hiddenStuff'] = $encryptedtext; $this->load->view('edit_mainconfig', $data); }
public static function set($name, $value, $config = NULL) { extract($config ?: config()->cookie); $value = $value ? base64_encode(Cipher::encrypt(json_encode(array(time(), $value)), $key)) : ''; setcookie($name, $value, $expires, $path, $domain, $secure, $httponly); }
/** * Encrypt the given value so that it's unreadable and that it can be used in an url. * * @param string $value * * @return string */ public function encrypt($value) { return bin2hex(parent::encrypt($value)); }
$params['key'] = $key; if ("ECB" != $block && isset($_GET["iv"]) && strlen($_GET["iv"]) > 0) { $iv = $_GET["iv"]; } if ("encrypt" === $_GET["mode"]) { // 暗号処理 $decrypt = $val; if (null !== $iv) { if ("base64" === $_GET["format"]) { $iv = base64_decode($iv); } elseif ("hex" === $_GET["format"]) { $iv = pack("H*", $iv); } } $params['iv'] = $iv; $encrypt = Cipher::encrypt($params); $iv = Cipher::getNowIV(); if ("base64" === $_GET["format"]) { $encrypt = base64_encode($encrypt); $iv = base64_encode($iv); } elseif ("hex" === $_GET["format"]) { $encrypt = bin2hex($encrypt); $iv = bin2hex($iv); } } elseif ("decrypt" === $_GET["mode"]) { // 復号処理 $encrypt = $val; if ("base64" === $_GET["format"]) { $encrypt = base64_decode($encrypt); $iv = base64_decode($iv); } elseif ("hex" === $_GET["format"]) {
<?php include '../core/Page.php'; $c = new Cipher('aabb'); echo $c->encrypt('Poopie'); echo '<HR>'; echo $c->decrypt($c->encrypt('Poopie'));
<?php /** * Created by PhpStorm. * User: USER * Date: 7/6/2015 * Time: 20:28 */ class Cipher { private $securekey, $iv; function __construct($textkey) { $this->securekey = hash('sha256', $textkey, TRUE); $this->iv = mcrypt_create_iv(32); } function encrypt($input) { return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->securekey, $input, MCRYPT_MODE_ECB, $this->iv)); } function decrypt($input) { return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->securekey, base64_decode($input), MCRYPT_MODE_ECB, $this->iv)); } } $cipher = new Cipher('secret passphrase'); $encryptedtext = $cipher->encrypt("hide me"); echo "->encrypt = {$encryptedtext}<br />"; $decryptedtext = $cipher->decrypt($encryptedtext); echo "->decrypt = {$decryptedtext}<br />"; var_dump($cipher);
/** * Called before any output is sent to create an encrypted cookie with the given value. * * @param string $key cookie name * @param mixed $value to save * @param array $config settings * return boolean */ public static function set($name, $value, $config) { extract($config); // If the cookie is being removed we want it left blank if ($value) { $value = Cipher::encrypt(json_encode(array(time(), $value)), $key); } // Update the current cookie global $_COOKIE[$name] = $value; // Save cookie to user agent setcookie($name, $value, $expires, $path, $domain, $secure, $httponly); }
function make_api_key($username, $password) { // this is simply an encryption for username and password that will work as an alternative way to log in for remote access pages such as rss and apis // this is simply to avoid sending username and password plainly in the url. global $api_scramble_key; if (extension_loaded('mcrypt') && extension_loaded('hash')) { $cipher = new Cipher($api_scramble_key); return $cipher->encrypt($username . "|" . $password, $api_scramble_key); } else { return strtr(base64_encode(convert($username . "|" . $password, $api_scramble_key)), '+/=', '-_,'); } }
<?php /* testing file */ /* move this file to your MediaWiki directory if you're too lazy to re-set this requires */ require_once "PEAR.php"; require_once "Crypt/RSA.php"; require_once "extensions/PageProtection/Cipher.php"; /* try to add more characters to key 1234555.... to cause error */ $c = new Cipher('blowfish', '1234555555555555555555555'); if ($c->has_error()) { print "An error has occured: " . $c->get_last_error() . "\n"; exit; } $tekst = "plain text siefca"; $encoded = $c->encrypt($tekst); $key = $c->mLastKey; $iv = $c->mLastIV; $cipher = $c->mLastCipher; $result = $c->decrypt($encoded, $cipher, $key, $iv); print "alghoritm: {$cipher}\n"; print "plaintext: {$result}" . "\n";