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


PHP openssl_cipher_iv_length函数代码示例

本文整理汇总了PHP中openssl_cipher_iv_length函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_cipher_iv_length函数的具体用法?PHP openssl_cipher_iv_length怎么用?PHP openssl_cipher_iv_length使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: __construct

 function __construct()
 {
     $this->iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
     $this->Key = sha1("Patronato Santo Antonio");
     //NÃO ALTERAR ESSA LINHA
     $this->Method = 'AES-256-CBC';
 }
开发者ID:claytongf,项目名称:patr,代码行数:7,代码来源:Cript.php

示例2: decrypt

 /**
  * Decrypt a string.
  *
  * @access public
  * @static static method
  * @param  string $ciphertext
  * @return string
  * @throws Exception If $ciphertext is empty, or If functions don't exists
  */
 public static function decrypt($ciphertext)
 {
     if (empty($ciphertext)) {
         throw new Exception("the string to decrypt can't be empty");
     }
     if (!function_exists('openssl_cipher_iv_length') || !function_exists('openssl_decrypt')) {
         throw new Exception("Encryption function don't exists");
     }
     // generate key used for authentication using ENCRYPTION_KEY & HMAC_SALT
     $key = mb_substr(hash(self::HASH_FUNCTION, Config::get('ENCRYPTION_KEY') . Config::get('HMAC_SALT')), 0, 32, '8bit');
     // split cipher into: hmac, cipher & iv
     $macSize = 64;
     $hmac = mb_substr($ciphertext, 0, $macSize, '8bit');
     $iv_cipher = mb_substr($ciphertext, $macSize, null, '8bit');
     // generate original hmac & compare it with the one in $ciphertext
     $originalHmac = hash_hmac('sha256', $iv_cipher, $key);
     if (!function_exists("hash_equals")) {
         throw new Exception("Function hash_equals() doesn't exist!");
     }
     if (!hash_equals($hmac, $originalHmac)) {
         return false;
     }
     // split out the initialization vector and cipher
     $iv_size = openssl_cipher_iv_length(self::CIPHER);
     $iv = mb_substr($iv_cipher, 0, $iv_size, '8bit');
     $cipher = mb_substr($iv_cipher, $iv_size, null, '8bit');
     return openssl_decrypt($cipher, self::CIPHER, $key, OPENSSL_RAW_DATA, $iv);
 }
开发者ID:scienide00,项目名称:WebDev_ConferenceScheduler,代码行数:37,代码来源:Encryption.php

示例3: incrementCounter

 /**
  * Increment a counter (prevent nonce reuse)
  *
  * @param string $ctr - raw binary
  * @param int $inc - how much?
  *
  * @return string (raw binary)
  */
 public static function incrementCounter($ctr, $inc, &$config)
 {
     static $ivsize = null;
     if ($ivsize === null) {
         $ivsize = \openssl_cipher_iv_length($config->cipherMethod());
         if ($ivsize === false) {
             throw new Ex\CannotPerformOperationException("Problem obtaining the correct nonce length.");
         }
     }
     if (self::ourStrlen($ctr) !== $ivsize) {
         throw new Ex\CannotPerformOperationException("Trying to increment a nonce of the wrong size.");
     }
     if (!is_int($inc)) {
         throw new Ex\CannotPerformOperationException("Trying to increment nonce by a non-integer.");
     }
     if ($inc < 0) {
         throw new Ex\CannotPerformOperationException("Trying to increment nonce by a negative amount.");
     }
     /**
      * We start at the rightmost byte (big-endian)
      * So, too, does OpenSSL: http://stackoverflow.com/a/3146214/2224584
      */
     for ($i = $ivsize - 1; $i >= 0; --$i) {
         $sum = \ord($ctr[$i]) + $inc;
         /* Detect integer overflow and fail. */
         if (!is_int($sum)) {
             throw new Ex\CannotPerformOperationException("Integer overflow in CTR mode nonce increment.");
         }
         $ctr[$i] = \chr($sum & 0xff);
         $inc = $sum >> 8;
     }
     return $ctr;
 }
开发者ID:robstoll,项目名称:PuMa,代码行数:41,代码来源:Core.php

示例4: _validateIV

 /**
  * Check that IV is valid.
  *
  * @param string $iv
  * @throws \RuntimeException
  */
 protected final function _validateIV($iv)
 {
     $len = openssl_cipher_iv_length($this->_getCipherMethod());
     if ($len != strlen($iv)) {
         throw new \RuntimeException("Invalid IV length.");
     }
 }
开发者ID:sop,项目名称:jwx,代码行数:13,代码来源:AESCBCAlgorithm.php

示例5: decrypt

 /**
  * Decrypt a value using AES-256.
  *
  * @param string $cipher The ciphertext to decrypt.
  * @param string $key The 256 bit/32 byte key to use as a cipher key.
  * @return string Decrypted data. Any trailing null bytes will be removed.
  * @throws \InvalidArgumentException On invalid data or key.
  */
 public static function decrypt($cipher, $key)
 {
     $method = 'AES-256-CBC';
     $ivSize = openssl_cipher_iv_length($method);
     $iv = substr($cipher, 0, $ivSize);
     $cipher = substr($cipher, $ivSize);
     return openssl_decrypt($cipher, $method, $key, true, $iv);
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:16,代码来源:OpenSsl.php

示例6: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $key = openssl_random_pseudo_bytes(32);
     $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
     $output->writeln("KEY: " . $this->strtohex($key));
     $output->writeln("IV: " . $this->strtohex($iv));
 }
开发者ID:linkorb,项目名称:objectstorage,代码行数:7,代码来源:GenerateKeyCommand.php

示例7: decrypt

 /**
  * Decrypts payload and returns original data.
  * @return string|false Original data as string or string containing binary data, false if unsuccessful.
  */
 public static function decrypt($payload, $cipherParams)
 {
     $raw = defined('OPENSSL_RAW_DATA') ? OPENSSL_RAW_DATA : true;
     $ivLength = openssl_cipher_iv_length($cipherParams->getAlgorithmString());
     $iv = substr($payload, 0, $ivLength);
     $ciphertext = substr($payload, $ivLength);
     return openssl_decrypt($ciphertext, $cipherParams->getAlgorithmString(), $cipherParams->key, $raw, $iv);
 }
开发者ID:ably,项目名称:ably-php,代码行数:12,代码来源:Crypto.php

示例8: decryptText

function decryptText($text)
{
    $secret = defined("ENCRYPT_SECRET") ? ENCRYPT_SECRET : "something";
    $text = base64_decode($text);
    $iv_size = openssl_cipher_iv_length("aes-256-cbc");
    $iv = substr($text, 0, $iv_size);
    return openssl_decrypt(substr($text, $iv_size), 'aes-256-cbc', $secret, 0, $iv);
}
开发者ID:petrofcikmatus,项目名称:simple-todo,代码行数:8,代码来源:tasks.php

示例9: decrypted

 private function decrypted(string $hash) : string
 {
     $binary = hex2bin($hash);
     $ivSize = openssl_cipher_iv_length(self::CIPHER);
     $iv = substr($binary, self::BEGIN, $ivSize);
     $cipherText = substr(substr($binary, $ivSize), self::BEGIN, self::MAC_LENGTH);
     return openssl_decrypt($cipherText, self::CIPHER, $this->key(), OPENSSL_RAW_DATA, $iv);
 }
开发者ID:klapuch,项目名称:encryption,代码行数:8,代码来源:AES256CBC.php

示例10: decrypt

 /**
  * Decrypt a value using AES-256.
  *
  * @param string $cipher The ciphertext to decrypt.
  * @param string $key The 256 bit/32 byte key to use as a cipher key.
  * @return string Decrypted data. Any trailing null bytes will be removed.
  * @throws \InvalidArgumentException On invalid data or key.
  */
 public static function decrypt($cipher, $key)
 {
     $method = 'AES-256-CBC';
     $ivSize = openssl_cipher_iv_length($method);
     $iv = mb_substr($cipher, 0, $ivSize, '8bit');
     $cipher = mb_substr($cipher, $ivSize, null, '8bit');
     return openssl_decrypt($cipher, $method, $key, OPENSSL_RAW_DATA, $iv);
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:16,代码来源:OpenSsl.php

示例11: testIv

 /**
  * @test
  */
 public function testIv()
 {
     $algorithm = 'aes-256-cbc';
     $crypt = new OpenSSL($algorithm);
     $ivSize = openssl_cipher_iv_length($algorithm);
     $this->assertSame($ivSize, $crypt->getIvSize());
     $iv = $crypt->createIv();
     $this->assertEquals($ivSize, strlen($iv));
 }
开发者ID:shrikeh,项目名称:crypto,代码行数:12,代码来源:OpenSSLTest.php

示例12: encrypt

 private function encrypt($export, $output)
 {
     $key = base64_decode($export['encryptionKey']);
     if (strlen($key) != 32) {
         throw new \RuntimeException('The key must have the length of 32 bytes!');
     }
     $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::ENCRYPTION_ALGORITHM));
     return base64_encode($iv . openssl_encrypt(json_encode($output), self::ENCRYPTION_ALGORITHM, $key, true, $iv));
 }
开发者ID:zyxist,项目名称:cantiga,代码行数:9,代码来源:ExportCommand.php

示例13: decrypt

 /**
  * Decrypt provided data using AES 256 algorithm and the security.encryption.key.
  *
  * @param string $data
  *
  * @return string
  *
  * @since 1.2.2
  */
 public static function decrypt($data)
 {
     $config = ConfigProvider::getInstance();
     $ivsize = openssl_cipher_iv_length('aes-256-ecb');
     $iv = mb_substr($data, 0, $ivsize, '8bit');
     $ciphertext = mb_substr($data, $ivsize, null, '8bit');
     $decryptedData = openssl_decrypt($ciphertext, 'aes-256-ecb', $config->get('security.encryption.key'), OPENSSL_RAW_DATA, $iv);
     return $decryptedData;
 }
开发者ID:alphadevx,项目名称:alpha,代码行数:18,代码来源:SecurityUtils.php

示例14: encrypt

function encrypt($text)
{
    $fp = fopen('../other/key.txt', 'r');
    $key = fread($fp, filesize('../other/key'));
    fclose($fp);
    $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
    $encrypted = openssl_encrypt($text, 'aes-256-cbc', $key, 0, $iv);
    $encrypted = $encrypted . ':' . bin2hex($iv);
    return $encrypted;
}
开发者ID:TenderFishrig,项目名称:Books4Cash,代码行数:10,代码来源:crypting.php

示例15: decrypt

 /**
  * {@inheritDoc}
  */
 public function decrypt($data, $salt)
 {
     $password = $this->generatePassword($salt);
     $vectorSize = openssl_cipher_iv_length($this->method);
     $decrypted = base64_decode($data);
     $initializationVector = substr($decrypted, 0, $vectorSize);
     $decrypted = substr($decrypted, $vectorSize);
     $decrypted = openssl_decrypt($decrypted, $this->method, $password, OPENSSL_RAW_DATA, $initializationVector);
     return $decrypted;
 }
开发者ID:fivelab,项目名称:cryptography,代码行数:13,代码来源:OpenSslCryptography.php


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