function decrypt(string $key, string $nonce, string $aad, string $ciphertext, string $tag) : string { $cipher = new Cipher(); $context = $cipher->init($key, $nonce); $cipher->aad($context, $aad); $plaintext = $cipher->decrypt($context, $ciphertext); $cipher->finish($context, $tag); return $plaintext; }
function Get($Setting) { if (isset($_SESSION[$this->SessionName][$Setting]) && !empty($_SESSION[$this->SessionName][$Setting])) { if ($this->encrypted) { return Cipher::decrypt($_SESSION[$this->SessionName][$Setting]); } else { return $_SESSION[$this->SessionName][$Setting]; } } else { return ''; } }
public static function get($name, $config = NULL) { $config = $config ?: config()->cookie; if (isset($_COOKIE[$name])) { if ($v = json_decode(Cipher::decrypt(base64_decode($_COOKIE[$name]), $config['key']))) { if ($v[0] < $config['timeout']) { return is_scalar($v[1]) ? $v[1] : (array) $v[1]; } } } return FALSE; }
/** * Decrypt and fetch cookie data * * @param string $name of cookie * @param array $config settings * @return mixed */ public static function get($name, $config = NULL) { // Use default config settings if needed $config = $config ?: static::$settings; if (isset($_COOKIE[$name])) { // Decrypt cookie using cookie key if ($v = json_decode(Cipher::decrypt(base64_decode($_COOKIE[$name]), $config['key']))) { // Has the cookie expired? if ($v[0] < $config['timeout']) { return is_scalar($v[1]) ? $v[1] : (array) $v[1]; } } } return FALSE; }
function decrypt_api_key($key) { global $api_scramble_key; if (extension_loaded('mcrypt') && extension_loaded('hash')) { $cipher = new Cipher($api_scramble_key); $key = $cipher->decrypt($key); } else { $key = convert(base64_decode(strtr($key, '-_,', '+/=')), $api_scramble_key); } return explode("|", $key); }
/** * @param string * @return string */ public function decrypt($data) { return $this->impl->decrypt($data); }
/** * AES暗号形式で暗号化されたデータを複号化する * @param $argValue デコードする値 * @param $argKey 暗号キー * @param $argIv IV * @return $encrypt 複号化データ */ public static function decryptAES($argValue, $argKey, $argIV = null, $argPrefix = '', $argSuffix = '') { // パラメータセット // XXX パラメータは定数で可変出来るようにする $params = array('value' => $argValue, 'key' => $argKey, 'iv' => $argIV, 'algorithm' => 'rijndael-128', 'mode' => 'cbc', 'prefix' => $argPrefix, 'suffix' => $argSuffix); // データを暗号化する $decrypt = Cipher::decrypt($params); // エラー処理 if (false === $decrypt || NULL === $decrypt) { return false; } return $decrypt; }
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 */ print "algorithm: {$cipher}\n"; print "previous key: " . base64_encode($key) . "\n"; print "previous IV: " . base64_encode($iv) . "\n\n"; print "plaintext: {$result}\n";
} 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)); } } //Check if its a default installation. if (isset($_POST['wwdb'])) { if ($_POST['wwdb'] == "1") { //Get details from decrypter $cipher = new Cipher('transferDB@321'); $decryptedtext = $cipher->decrypt($_POST['hiddenstuff']); $dbDetails = unserialize($decryptedtext); $dbhost = $dbDetails['host']; $dbUname = $dbDetails['database_username']; $dbPassword = $dbDetails['database_password']; $dbName = $_POST['ConfigName']; } else { $dbhost = $_POST['databasehost']; $dbUname = $_POST['databaseusername']; $dbPassword = $_POST['databasepassword']; $dbName = $_POST['databasename']; } } else { $dbhost = $_POST['databasehost']; $dbUname = $_POST['databaseusername']; $dbPassword = $_POST['databasepassword'];
/** * Decrypt the given value so that it's readable again. * * @param string $value * * @return string */ public function decrypt($value) { return parent::decrypt($this->hex2bin($value)); }
$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"]) { $encrypt = pack("H*", $encrypt); $iv = pack("H*", $iv); } $params['value'] = $encrypt; $params['iv'] = $iv; $decrypt = Cipher::decrypt($params); if ("base64" === $_GET["format"]) { $encrypt = base64_encode($encrypt); $iv = base64_encode($iv); } elseif ("hex" === $_GET["format"]) { $encrypt = bin2hex($encrypt); $iv = bin2hex($iv); } } $responce = "<br/>"; $responce .= "入出力フォーマット:" . $_GET["format"] . "<br/>"; $responce .= "IV:「" . $iv . "」<br/>"; $responce .= "Key:「" . $key . "」<br/>"; $responce .= "decrypt:「" . $decrypt . "」<br/>"; $responce .= "encrypt:「" . $encrypt . "」<br/>"; }
<?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);
/** * Decrypt and fetch cookie data as long as the cookie has not expired * * @param string $name of cookie * @param array $config settings * @return mixed */ public static function get($name, $config = NULL) { if (isset($_COOKIE[$name])) { if ($value = json_decode(Cipher::decrypt($_COOKIE[$name], $config['key']), TRUE)) { if ($value[0] < time() + $config['timeout']) { return $value[1]; } } } return FALSE; }