• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP openssl_cipher_iv_length函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例6: 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


示例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


示例16: __construct

 /**
  *
  * @param string $cipher
  * @param string $password
  * @param string $salt
  * @param int $ivMaxChars null if you want a full iv. If you provide a number, the rest of the iv will be padded.
  * @param bool $useMd5NotRandom If true, the IV will be extracted from md5 of the data.
  * @param int $nonceChars
  * @param int $cipherIvLength If null, the iv length gets calculated with openssl_cipher_iv_length()
  * @param string $serializationFormat
  */
 public function __construct($cipher, $password, $salt, $ivMaxChars = 4, $useMd5NotRandom = false, $nonceChars = 5, $cipherIvLength = null, $serializationFormat = self::SERIALIZE_JSON)
 {
     parent::__construct($password, $salt, $serializationFormat);
     $this->cipher = $cipher;
     $cipherIvLength = (int) $cipherIvLength;
     $this->cipherIvLength = $cipherIvLength ? (int) $cipherIvLength : openssl_cipher_iv_length($this->cipher);
     $this->ivMaxChars = $ivMaxChars === null ? null : (int) $ivMaxChars;
     $this->nonceChars = (int) $nonceChars;
     $this->useMd5NotRandom = $useMd5NotRandom;
 }
开发者ID:enyo,项目名称:rincewind,代码行数:21,代码来源:Ssl.php


示例17: encrypt

 public static function encrypt($key, $data, $method = null)
 {
     if ($method === null) {
         $method = app()->getEncryptionMethod();
     }
     $key = substr(hash('sha256', $key, true), 0, 16);
     $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
     $data = openssl_encrypt($data, $method, $key, 0, $iv);
     return base64_encode($data . '|' . bin2hex($iv));
 }
开发者ID:skipperbent,项目名称:pecee,代码行数:10,代码来源:Guid.php


示例18: encrypt

 /**
  * @inheritdoc
  */
 public function encrypt($data)
 {
     $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($this->cipher));
     $encryptedValue = openssl_encrypt(serialize($data), $this->cipher, $this->key, 0, $iv);
     if ($encryptedValue === false) {
         throw new EncryptionException("Failed to encrypt the data");
     }
     $iv = base64_encode($iv);
     $mac = $this->createHash($iv, $encryptedValue);
     $pieces = ["iv" => $iv, "value" => $encryptedValue, "mac" => $mac];
     return base64_encode(json_encode($pieces));
 }
开发者ID:scaleddynamics,项目名称:Opulence,代码行数:15,代码来源:Encrypter.php


示例19: decrypt

 /**
  * decrypts by using the given enc_method and hash_method.
  * @param $edata the encrypted string that we want to decrypt
  * @return the decrypted string.
  */
 public function decrypt($edata)
 {
     $e_arr = explode('$', $edata);
     if (count($e_arr) != 4) {
         throw new Exception('Given data is missing crucial sections.');
     }
     $this->config['enc_method'] = $e_arr[1];
     $this->config['hash_method'] = $e_arr[2];
     self::check_methods($this->config['enc_method'], $this->config['hash_method']);
     $iv = self::hashIV($this->config['key'], $this->config['hash_method'], openssl_cipher_iv_length($this->config['enc_method']));
     return openssl_decrypt($e_arr[3], $this->config['enc_method'], $this->config['key'], false, $iv);
 }
开发者ID:cls1991,项目名称:ryzomcore,代码行数:17,代码来源:mycrypt.php


示例20: encrypt

 public static function encrypt($password, $secret, $data)
 {
     //Generate a key by hashing the secret and password
     $key = hash_pbkdf2("sha256", $password, $secret, 1000, 32);
     //Generate initialisation vector
     $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('aes-256-cbc'));
     //Encrypt data using the given secret and generated iv.
     $encrypted_data = openssl_encrypt($data, 'aes-256-cbc', $key, 0, $iv);
     //Append iv to the encrypted data
     $encrypted_data .= '|' . base64_encode($iv);
     return $encrypted_data;
 }
开发者ID:d0x2f,项目名称:CaseFiles,代码行数:12,代码来源:Encryption.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP openssl_csr_export函数代码示例发布时间:2022-05-15
下一篇:
PHP openside函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap