当前位置: 首页>>代码示例>>PHP>>正文


PHP Crypt_AES::setIV方法代码示例

本文整理汇总了PHP中Crypt_AES::setIV方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypt_AES::setIV方法的具体用法?PHP Crypt_AES::setIV怎么用?PHP Crypt_AES::setIV使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Crypt_AES的用法示例。


在下文中一共展示了Crypt_AES::setIV方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: AESDecrypt

function AESDecrypt($ciphertext, $key, $IV)
{
    $aes = new Crypt_AES(CRYPT_MODE_ECB);
    $aes->setKey(characet($key));
    $aes->setIV(characet($IV));
    return $aes->decrypt(hex2bin($ciphertext));
}
开发者ID:abcdlzy,项目名称:webshell-manager,代码行数:7,代码来源:common.php

示例2: initAes

 protected function initAes($key, $iv, $keySize)
 {
     $this->aes = new \Crypt_AES();
     $this->aes->setKeyLength($keySize);
     $this->aesKey = $key;
     $this->aesIV = $iv;
     $this->aes->setKey($this->aesKey);
     $this->aes->setIV($this->aesIV);
 }
开发者ID:amegatron,项目名称:cryptoapi,代码行数:9,代码来源:CryptoApiHelper.php

示例3: decryptAES

 /**
  * Decrypt the provided data using AES cryptography with the provided key and IV
  *
  * @param string $data Data to decrypt
  * @param string $key Cipher key used to encrypt the data
  * @param string $iv IV used to encrypt the data
  * @param bool $base64Encoded Is the provided data Base64 encoded (defaults to true)
  * @return string Unencrypted data
  */
 public function decryptAES($data, $key, $iv, $base64Encoded = true)
 {
     $data = $base64Encoded ? base64_decode($data) : $data;
     $cipher = new \Crypt_AES();
     $cipher->setKey($key);
     $cipher->setIV($iv);
     $cipher->disablePadding();
     $decrypted = rtrim($cipher->decrypt($data));
     return $decrypted;
 }
开发者ID:ThemeSurgeon,项目名称:launchkey-php,代码行数:19,代码来源:PhpSecLibCryptService.php

示例4: testEncryptDecryptWithContinuousBuffer

 /**
  * @dataProvider continuousBufferCombos
  */
 public function testEncryptDecryptWithContinuousBuffer($mode, $plaintext, $iv, $key)
 {
     $aes = new Crypt_AES(constant($mode));
     $aes->enableContinuousBuffer();
     $aes->setIV($iv);
     $aes->setKey($key);
     $actual = '';
     for ($i = 0, $strlen = strlen($plaintext); $i < $strlen; ++$i) {
         $actual .= $aes->decrypt($aes->encrypt($plaintext[$i]));
     }
     $this->assertEquals($plaintext, $actual);
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:15,代码来源:TestCase.php

示例5: decrypt

 public static function decrypt($secret, $password, ApiKeyEncryptionOptions $options)
 {
     $decodedSecret = self::base64url_decode($secret);
     $salt = self::base64url_decode($options->getEncryptionKeySalt());
     $iterations = $options->getEncryptionKeyIterations();
     $keyLengthBits = $options->getEncryptionKeySize();
     $iv = substr($decodedSecret, 0, 16);
     $aes = new \Crypt_AES();
     $aes->setPassword($password, 'pbkdf2', 'sha1', $salt, $iterations, $keyLengthBits / 8);
     $aes->setKeyLength($keyLengthBits);
     $aes->setIV($iv);
     return $aes->decrypt(substr($decodedSecret, 16));
 }
开发者ID:InfinityCCS,项目名称:stormpath-sdk-php,代码行数:13,代码来源:ApiKeyEncryptionUtils.php

示例6: loginWSAuthenticate

/**
 * Checks whether a user has the right to enter on the platform or not
 * @param string The username, as provided in form
 * @param string The cleartext password, as provided in form
 * @param string The WS URL, as provided at the beginning of this script
 */
function loginWSAuthenticate($username, $password, $wsUrl)
{
    // check params
    if (empty($username) or empty($password) or empty($wsUrl)) {
        return false;
    }
    // Create new SOAP client instance
    $client = new SoapClient($wsUrl);
    if (!$client) {
        return false;
    }
    // Include phpseclib methods, because of a bug with AES/CFB in mcrypt
    include_once api_get_path(LIBRARY_PATH) . 'phpseclib/Crypt/AES.php';
    // Define all elements necessary to the encryption
    $key = '-+*%$({[]})$%*+-';
    // Complete password con PKCS7-specific padding
    $blockSize = 16;
    $padding = $blockSize - strlen($password) % $blockSize;
    $password .= str_repeat(chr($padding), $padding);
    $cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
    $cipher->setKeyLength(128);
    $cipher->setKey($key);
    $cipher->setIV($key);
    $cipheredPass = $cipher->encrypt($password);
    // Mcrypt call left for documentation purposes - broken, see https://bugs.php.net/bug.php?id=51146
    //$cipheredPass = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $password,  MCRYPT_MODE_CFB, $key);
    // Following lines present for debug purposes only
    /*
    $arr = preg_split('//', $cipheredPass, -1, PREG_SPLIT_NO_EMPTY);
    foreach ($arr as $char) {
        error_log(ord($char));
    }
    */
    // Change to base64 to avoid communication alteration
    $passCrypted = base64_encode($cipheredPass);
    // The call to the webservice will change depending on your definition
    try {
        $response = $client->validateUser(array('user' => $username, 'pass' => $passCrypted, 'system' => 'chamilo'));
    } catch (SoapFault $fault) {
        error_log('Caught something');
        if ($fault->faultstring != 'Could not connect to host') {
            error_log('Not a connection problem');
            throw $fault;
        } else {
            error_log('Could not connect to WS host');
        }
        return 0;
    }
    return $response->validateUserResult;
}
开发者ID:KRCM13,项目名称:chamilo-lms,代码行数:56,代码来源:login.ws.php

示例7: post_get_option_filter

 /**
  * Process the launchkey option to prepare for usage within the plugin.  The option will have encrypted attributes
  * decrypted as well as set default values for any missing or unset attributes.
  *
  * @since 1.0.0
  *
  * @param $input
  *
  * @return array
  */
 public function post_get_option_filter($input)
 {
     // Define the defaults for attributes
     $defaults = static::get_defaults();
     // If the input is empty (null) set it to an empty array
     $input ?: array();
     // Merge the input array over the defaults array to set any know data to the response
     $output = array_merge($defaults, $input);
     // If the secret key attribute is not empty, decrypt it
     if (!empty($input[LaunchKey_WP_Options::OPTION_SECRET_KEY])) {
         $key = md5($input[LaunchKey_WP_Options::OPTION_SECRET_KEY]);
         if (empty($this->cache[$key])) {
             /**
              * Use the rocket key as the IV. If null, use the static value.
              * @link https://docs.launchkey.com/glossary.html#term-iv
              */
             $iv = empty($output[LaunchKey_WP_Options::OPTION_ROCKET_KEY]) ? static::STATIC_IV : $output[LaunchKey_WP_Options::OPTION_ROCKET_KEY];
             $this->crypt_aes->setIV($iv);
             /**
              * Decrypt the Base64 decoded string and set it as the output value
              * @link https://docs.launchkey.com/glossary.html#term-base64
              */
             $this->cache[$key] = $this->crypt_aes->decrypt(base64_decode($input[LaunchKey_WP_Options::OPTION_SECRET_KEY]));
         }
         $output[LaunchKey_WP_Options::OPTION_SECRET_KEY] = $this->cache[$key];
     }
     // If the private key attribute is not empty, decrypt it
     if (!empty($input[LaunchKey_WP_Options::OPTION_PRIVATE_KEY])) {
         $key = md5($input[LaunchKey_WP_Options::OPTION_PRIVATE_KEY]);
         if (empty($this->cache[$key])) {
             /**
              * Use the decrypted secret key as the IV. If null, use the static value.
              * @link https://docs.launchkey.com/glossary.html#term-iv
              */
             $iv = empty($output[LaunchKey_WP_Options::OPTION_SECRET_KEY]) ? static::STATIC_IV : $output[LaunchKey_WP_Options::OPTION_SECRET_KEY];
             $this->crypt_aes->setIV($iv);
             /**
              * Decrypt the Base64 decoded string and set it as the output value
              * @link https://docs.launchkey.com/glossary.html#term-base64
              *
              * We are suppressing errors as
              */
             $this->cache[$key] = @$this->crypt_aes->decrypt(base64_decode($input[LaunchKey_WP_Options::OPTION_PRIVATE_KEY]));
         }
         $output[LaunchKey_WP_Options::OPTION_PRIVATE_KEY] = $this->cache[$key];
     }
     return $output;
 }
开发者ID:ThemeSurgeon,项目名称:launchkey-wordpress,代码行数:58,代码来源:class-launchkey-wp-options.php

示例8: initSymmetric

 /**
  * Initializes AES instance using either provided $options or session values
  * @param array $options Array of options, containing 'key' and 'iv' values
  * @return mixed|void
  * @throws Exception
  */
 public function initSymmetric($options = array())
 {
     if (empty($options) && Session::has('aes_key') && Session::has('aes_iv')) {
         $options = array('key' => Session::get('aes_key'), 'iv' => Session::get('aes_iv'));
     }
     if (!(isset($options['key']) && isset($options['iv']))) {
         \Log::error("Either key or iv not set");
         throw new \Exception("Either key or iv not set");
     }
     Session::put('aes_key', $options['key']);
     Session::put('aes_iv', $options['iv']);
     $aes = new \Crypt_AES(CRYPT_AES_MODE_CBC);
     $aes->setKeyLength(256);
     $aes->setKey(Base64::UrlDecode($options['key']));
     $aes->setIV(Base64::UrlDecode($options['iv']));
     $aes->enablePadding();
     $this->aes = $aes;
     $this->isAesInitialized = true;
 }
开发者ID:tiagogoddard,项目名称:cryptoapi,代码行数:25,代码来源:RsaAesCryptography.php

示例9: ExtractDataPacket

 static function ExtractDataPacket($data, $key, $options = array())
 {
     $data = (string) $data;
     if (!isset($options["mode"])) {
         $options["mode"] = "ECB";
     }
     if ($options["mode"] != "ECB" && (!isset($options["iv"]) || $options["iv"] == "")) {
         return false;
     }
     if (isset($options["key2"])) {
         $options2 = $options;
         if (isset($options["iv2"])) {
             $options["iv"] = $options["iv2"];
         } else {
             unset($options["iv"]);
         }
         if (self::IsMcryptAvailable()) {
             $data = self::McryptDecrypt($data, $options["key2"], $options);
         } else {
             if (class_exists("Crypt_AES")) {
                 $aes = new Crypt_AES($options["mode"] == "CBC" ? CRYPT_AES_MODE_CBC : CRYPT_AES_MODE_ECB);
                 $aes->setKey($options["key2"]);
                 if (isset($options["iv"])) {
                     $aes->setIV($options["iv"]);
                 }
                 $aes->disablePadding();
                 $data = $aes->decrypt($data);
             } else {
                 return false;
             }
         }
         $data = substr($data, 1) . substr($data, 0, 1);
         $options = $options2;
     }
     if (self::IsMcryptAvailable()) {
         $data = self::McryptDecrypt($data, $key, $options);
     } else {
         if (class_exists("Crypt_AES")) {
             $aes = new Crypt_AES($options["mode"] == "CBC" ? CRYPT_AES_MODE_CBC : CRYPT_AES_MODE_ECB);
             $aes->setKey($key);
             if (isset($options["iv"])) {
                 $aes->setIV($options["iv"]);
             }
             $aes->disablePadding();
             $data = $aes->decrypt($data);
         } else {
             return false;
         }
     }
     if ($data === false) {
         return false;
     }
     $pos = strpos($data, "\n");
     if ($pos === false) {
         return false;
     }
     $data = substr($data, $pos + 1);
     $pos = strpos($data, "\n");
     if ($pos === false) {
         return false;
     }
     $check = substr($data, 0, $pos);
     $data = substr($data, $pos + 1);
     $pos = strrpos($data, "\n");
     if ($pos === false) {
         return false;
     }
     $data = substr($data, 0, $pos);
     if (!isset($options["lightweight"]) || !$options["lightweight"]) {
         if ($check !== strtolower(sha1($data))) {
             return false;
         }
     } else {
         if ($check !== strtolower(dechex(crc32($data)))) {
             return false;
         }
     }
     return $data;
 }
开发者ID:marks2016,项目名称:sso,代码行数:79,代码来源:sso_aes.php

示例10: random

 function random($len)
 {
     if (CRYPT_IS_WINDOWS) {
         if (function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4', '>=')) {
             return openssl_random_pseudo_bytes($len);
         }
         // Looks like mcrypt_create_iv with MCRYPT_DEV_RANDOM is still
         // unreliable on 5.3.6:
         // https://bugs.php.net/bug.php?id=52523
         if (function_exists('mcrypt_create_iv') && version_compare(PHP_VERSION, '5.3.7', '>=')) {
             return mcrypt_create_iv($len);
         }
     } else {
         if (function_exists('openssl_random_pseudo_bytes')) {
             return openssl_random_pseudo_bytes($len);
         }
         static $fp = null;
         if ($fp == null) {
             $fp = @fopen('/dev/urandom', 'rb');
         }
         if ($fp) {
             return fread($fp, $len);
         }
         if (function_exists('mcrypt_create_iv')) {
             return mcrypt_create_iv($len, MCRYPT_DEV_URANDOM);
         }
     }
     $seed = session_id() . microtime() . getmypid();
     $key = pack('H*', sha1($seed . 'A'));
     $iv = pack('H*', sha1($seed . 'C'));
     $crypto = new Crypt_AES(CRYPT_AES_MODE_CTR);
     $crypto->setKey($key);
     $crypto->setIV($iv);
     $crypto->enableContinuousBuffer();
     //Sliding iv.
     $start = mt_rand(5, PHP_INT_MAX);
     $output = '';
     for ($i = $start; strlen($output) < $len; $i++) {
         $output .= $crypto->encrypt($i);
     }
     return substr($output, 0, $len);
 }
开发者ID:KingsleyGU,项目名称:osticket,代码行数:42,代码来源:class.crypto.php

示例11: _decrypt_chunk

 private function _decrypt_chunk($cipher_text, $last = false)
 {
     //Compute MAC on the ciphertext
     if ($this->compute_mac) {
         $this->_mac_chunk($cipher_text, $last);
     }
     //Perform decryption
     $aes = new \Crypt_AES();
     $aes->setKey($this->key);
     $aes->setIV($this->next_iv);
     //if this is not the last chunk, we will need to reconstruct the
     //encrypted padding block
     if (!$last) {
         $dummy_iv = substr($cipher_text, -16);
         $dummy_plain = FileEncryptor::pack('C*', array_pad(array(), 16, 16));
         $dummy_aes = new \Crypt_AES();
         $dummy_aes->setKey($this->key);
         $dummy_aes->setIV($dummy_iv);
         $dummy_cipher = $dummy_aes->encrypt($dummy_plain);
         //$dummy_cipher itself has a dummy block which needs to be removed
         $dummy_block = substr($dummy_cipher, 0, -16);
         $cipher_text = $cipher_text . $dummy_block;
         $this->next_iv = $dummy_iv;
     }
     $plain_text = $aes->decrypt($cipher_text);
     return $plain_text;
 }
开发者ID:robisacommonusername,项目名称:rran-site,代码行数:27,代码来源:FileEncryptor.php

示例12: SendEncryptedResponse

function SendEncryptedResponse($message)
{
    $aes = new Crypt_AES(CRYPT_AES_MODE_CBC);
    $aes->setKeyLength(256);
    $aes->setKey(Base64UrlDecode($_SESSION['key']));
    $aes->setIV(Base64UrlDecode($_SESSION['iv']));
    $aes->enablePadding();
    // This is PKCS
    echo Base64UrlEncode($aes->encrypt($message));
    exit;
}
开发者ID:rajeshwarn,项目名称:csharp-to-php-encryption,代码行数:11,代码来源:secure.php

示例13: base64_encode

<?php

//
// Copyright (c) 2011 Scott Clayton
//
// This file is part of the C# to PHP Encryption Library.
//
// The C# to PHP Encryption Library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The C# to PHP Encryption Library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with the C# to PHP Encryption Library.  If not, see <http://www.gnu.org/licenses/>.
//
include 'Crypt/AES.php';
$aes = new Crypt_AES();
$aes->setKey('abcdefghijklmnopabcdefghijklmnop');
$aes->setIV('abcdefghijklmnop');
$aes->setKeyLength(256);
echo base64_encode("abcdefghijklmnopabcdefghijklmnop") . "<BR>";
echo base64_encode("abcdefghijklmnop") . "<BR>";
$plaintext = 'llamas are super cool!';
echo base64_encode($aes->encrypt($plaintext)) . "<BR>";
echo $aes->decrypt($aes->encrypt($plaintext));
开发者ID:rajeshwarn,项目名称:csharp-to-php-encryption,代码行数:30,代码来源:aes.php

示例14: login_get

 public function login_get()
 {
     cacheHeaders(false);
     $this->load->Model('Vip');
     $this->load->Model('User');
     $username = $this->get('username');
     $password = $this->get('password');
     $flavour = $this->get('flavour');
     $token = $this->get('token');
     $socialnetwork = $this->get('socialnetwork');
     $newsletter = $this->get('newsletter');
     if (!$flavour) {
         $flavour = 'yousee';
     }
     if (!$password) {
         $password = $this->input->server('HTTP_X_PASSWORD');
     }
     // if token is set and socialnetwork is not
     // we assume old school token
     if ($token && !$socialnetwork) {
         $this->load->library('encrypt');
         $decrypted = $this->encrypt->decode(base64_decode($token));
         if ($decrypted) {
             $foo = explode('||||', $decrypted);
             if (is_array($foo) && count($foo) == 2) {
                 $username = $foo[0];
                 $password = $foo[1];
             }
         }
     }
     $apikey = $this->rest->key;
     $useencryption = !empty($this->sharedsecrets[$apikey]['key']) && $this->get('enc');
     if ($useencryption) {
         $enctype = $this->sharedsecrets[$apikey]['type'];
         if ($enctype == 'ios') {
             $password = $this->input->server('HTTP_X_PASSWORD');
             $password = @mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->sharedsecrets[$apikey]['key'], base64_decode($password), MCRYPT_MODE_CBC);
             $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
         } else {
             if ($enctype == 'android-blockbuster') {
                 $password = $this->input->server('HTTP_X_PASSWORD');
                 $cipher = new Crypt_AES();
                 $cipher->setKey($this->sharedsecrets[$apikey]['key']);
                 $cipher->setIV($this->sharedsecrets[$apikey]['iv']);
                 $password = $cipher->decrypt(base64_decode($password));
             }
         }
     }
     $presentableError = null;
     if ($flavour == 'yousee') {
         $session_id = Facades\YSPRO::login($username, $password);
         if ($session_id) {
             $domain = 'xmpp.yousee.tv';
             $userinfo = Facades\YSPRO::getUserInfo($session_id);
             if ($this->get('flavour') == 'yousee' && !$userinfo->customerNumber) {
                 // only do this for new apps
                 // WAT?
                 // we don't want the old school users with customer numbers
                 $allowLogin = false;
                 $allowLogin = $isVip = $this->Vip->hasAccess($userinfo->userId, Vip::TVWEBLARGE) || $this->Vip->hasAccess($userinfo->userId, Vip::ARCHIVE) || $this->Vip->hasAccess($userinfo->userId, Vip::TVWEBSMALL) || $this->Vip->hasAccess($userinfo->userId, Vip::MOVIE) || $this->Vip->hasAccess($userinfo->userId, Vip::HBO) || $this->Vip->hasAccess($userinfo->userId, Vip::CMORE) || $this->Vip->hasAccess($userinfo->userId, Vip::YOUBIO);
                 $cacheInstance = new \OdpCaching\Memcache(\OdpConfig\Config::getInstance()->getMemcacheServerpool());
                 $ysproInstance = new \OdpYspro\Yspro($cacheInstance);
                 if (!$allowLogin) {
                     // oh boy - we also need to check if the customer is a YouSee mobile customer
                     // provisioned through YSPro
                     $youseeMobile = new \OdpPermissions\YouSeeMobile($cacheInstance, $ysproInstance, $userinfo);
                     $allowLogin = $youseeMobile->getPermission()->permission;
                 }
                 if (!$allowLogin) {
                     // Play music users must be allowed to login
                     $umapEngagement = $ysproInstance->getUmapEngagementForUserId($userinfo->userId);
                     $allowLogin = !empty($umapEngagement['MSISDN']);
                 }
                 if (!$allowLogin) {
                     // DkTv users must be allowed to login
                     $allowLogin = with(new \OdpPermissions\DkTv($cacheInstance, $ysproInstance, $userinfo))->canLogin();
                 }
                 if (!$allowLogin) {
                     return $this->returnRestError(1052, 'Login does not grant access to app', 'Du har forsøgt at logge ind med et login uden tilknyttede YouSee produkter. Benyt i stedet dit YouSee Login, som du finder på yousee.dk under "Mit YouSee".', 400, false, true, $userinfo);
                 }
             }
         } else {
             $presentableError = 'Du har indtastet forkert brugernavn eller adgangskode';
         }
     } else {
         if ($flavour == 'tdc') {
             $session_id = Facades\CoreID::login($username, $password);
             if ($session_id) {
                 $domain = 'xmpp.tdc.dk';
                 $userinfo = Facades\CoreID::getUserInfo($session_id);
             } else {
                 $tdcError = Facades\CoreID::getLastTdcError();
                 if ($tdcError) {
                     if ($tdcError = 1) {
                         $presentableError = 'Du har indtastet forkert brugernavn eller adgangskode';
                     } else {
                         if ($tdcError = 2) {
                             $presentableError = 'Dit login er spærret i 12 timer, da du har forsøgt at logge på med forkert adgangskode 10 gange';
                         } else {
                             if ($tdcError = 4) {
//.........这里部分代码省略.........
开发者ID:staticweb,项目名称:webfilter,代码行数:101,代码来源:users.php

示例15: cookieDecrypt

 /**
  * Decryption using openssl's AES or phpseclib's AES
  * (phpseclib uses mcrypt when it is available)
  *
  * @param string $encdata encrypted data
  * @param string $secret  the secret
  *
  * @return string original data
  */
 public function cookieDecrypt($encdata, $secret)
 {
     if (is_null($this->_cookie_iv)) {
         $this->_cookie_iv = base64_decode($_COOKIE['pma_iv-' . $GLOBALS['server']], true);
     }
     if (strlen($this->_cookie_iv) < $this->getIVSize()) {
         $this->createIV();
     }
     if ($this->_useOpenSSL()) {
         return openssl_decrypt($encdata, 'AES-128-CBC', $secret, 0, $this->_cookie_iv);
     } else {
         $cipher = new Crypt_AES(CRYPT_AES_MODE_CBC);
         $cipher->setIV($this->_cookie_iv);
         $cipher->setKey($secret);
         return $cipher->decrypt(base64_decode($encdata));
     }
 }
开发者ID:siddhantsomani,项目名称:phpmyadmin,代码行数:26,代码来源:AuthenticationCookie.class.php


注:本文中的Crypt_AES::setIV方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。