예제 #1
0
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;
}
예제 #2
0
 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 '';
     }
 }
예제 #3
0
 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;
 }
예제 #4
0
 /**
  * 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;
 }
예제 #5
0
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);
}
예제 #6
0
파일: CipherProxy.php 프로젝트: rsms/phpab
 /**
  * @param  string
  * @return string
  */
 public function decrypt($data)
 {
     return $this->impl->decrypt($data);
 }
예제 #7
0
 /**
  * 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;
 }
예제 #8
0
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";
예제 #9
0
    }
    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'];
예제 #10
0
 /**
  * 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));
 }
예제 #11
0
             $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/>";
 }
예제 #12
0
파일: ciphertest.php 프로젝트: h3rb/page
<?php

include '../core/Page.php';
$c = new Cipher('aabb');
echo $c->encrypt('Poopie');
echo '<HR>';
echo $c->decrypt($c->encrypt('Poopie'));
예제 #13
0
<?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);
예제 #14
0
파일: Core.php 프로젝트: xeoncross/kit
 /**
  * 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;
 }