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


PHP Crypto::CreateNewRandomKey方法代码示例

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


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

示例1: set_session

 /**
  * [set_session 设置session]
  * @param [type] $user[用户信息]
  */
 public function set_session($user)
 {
     session_start();
     $_SESSION[$this->login_in_session_name] = $user;
     $key = Crypto::CreateNewRandomKey();
     $safe_session_id = base64_encode($key . Crypto::Encrypt(session_id(), $key));
     return $safe_session_id;
 }
开发者ID:897475686,项目名称:bbm,代码行数:12,代码来源:auth_service.php

示例2: createDocument

 public function createDocument($title, $plainContent, User $creator, $passPhrase)
 {
     $key = \Crypto::CreateNewRandomKey();
     $encryptedKey = KeyGen::encrypt($key, $creator->getPublicKey());
     $document = new Document($creator, $encryptedKey);
     $this->documentRepository->persist($document->getShares()[0]);
     $this->updateDocument($document, $title, $plainContent, $creator, $passPhrase);
     return $document;
 }
开发者ID:trivago-tgoik,项目名称:kis,代码行数:9,代码来源:DocumentService.php

示例3: TestEncryptDecrypt

 private static function TestEncryptDecrypt()
 {
     $key = Crypto::CreateNewRandomKey();
     $data = "EnCrYpT EvErYThInG";
     // Make sure encrypting then decrypting doesn't change the message.
     $ciphertext = Crypto::Encrypt($data, $key);
     try {
         $decrypted = Crypto::Decrypt($ciphertext, $key);
     } catch (InvalidCiphertextException $ex) {
         // It's important to catch this and change it into a
         // CryptoTestFailedException, otherwise a test failure could trick
         // the user into thinking it's just an invalid ciphertext!
         throw new CryptoTestFailedException();
     }
     if ($decrypted !== $data) {
         throw new CryptoTestFailedException();
     }
     // Modifying the ciphertext: Appending a string.
     try {
         Crypto::Decrypt($ciphertext . "a", $key);
         throw new CryptoTestFailedException();
     } catch (InvalidCiphertextException $e) {
         /* expected */
     }
     // Modifying the ciphertext: Changing an IV byte.
     try {
         $ciphertext[0] = chr((ord($ciphertext[0]) + 1) % 256);
         Crypto::Decrypt($ciphertext, $key);
         throw new CryptoTestFailedException();
     } catch (InvalidCiphertextException $e) {
         /* expected */
     }
     // Decrypting with the wrong key.
     $key = Crypto::CreateNewRandomKey();
     $data = "abcdef";
     $ciphertext = Crypto::Encrypt($data, $key);
     $wrong_key = Crypto::CreateNewRandomKey();
     try {
         Crypto::Decrypt($ciphertext, $wrong_key);
         throw new CryptoTestFailedException();
     } catch (InvalidCiphertextException $e) {
         /* expected */
     }
     // Ciphertext too small (shorter than HMAC).
     $key = Crypto::CreateNewRandomKey();
     $ciphertext = str_repeat("A", self::MAC_BYTE_SIZE - 1);
     try {
         Crypto::Decrypt($ciphertext, $key);
         throw new CryptoTestFailedException();
     } catch (InvalidCiphertextException $e) {
         /* expected */
     }
 }
开发者ID:deenison,项目名称:joomla-cms,代码行数:53,代码来源:Crypto.php

示例4: catch

<?php

require_once 'Crypto.php';
try {
    $key = Crypto::CreateNewRandomKey();
    // WARNING: Do NOT encode $key with bin2hex() or base64_encode(),
    // they may leak the key to the attacker through side channels.
} catch (CryptoTestFailedException $ex) {
    die('Cannot safely create a key');
} catch (CannotPerformOperationException $ex) {
    die('Cannot safely create a key');
}
$message = "ATTACK AT DAWN";
try {
    $ciphertext = Crypto::Encrypt($message, $key);
} catch (CryptoTestFailedException $ex) {
    die('Cannot safely perform encryption');
} catch (CannotPerformOperationException $ex) {
    die('Cannot safely perform decryption');
}
try {
    $decrypted = Crypto::Decrypt($ciphertext, $key);
} catch (InvalidCiphertextException $ex) {
    // VERY IMPORTANT
    // Either:
    //   1. The ciphertext was modified by the attacker,
    //   2. The key is wrong, or
    //   3. $ciphertext is not a valid ciphertext or was corrupted.
    // Assume the worst.
    die('DANGER! DANGER! The ciphertext has been tampered with!');
} catch (CryptoTestFailedException $ex) {
开发者ID:ZerGabriel,项目名称:friendica,代码行数:31,代码来源:example.php

示例5: getEncryptionKey

 /**
  * Retrieves the encryption key from cache, or generations a new one in the instance one does not exists
  * @return string
  */
 public static function getEncryptionKey()
 {
     $key = self::getConfig('encryptionKey', NULL, 'settings_', true);
     if ($key == NULL || $key == "") {
         try {
             $key = Crypto::CreateNewRandomKey();
         } catch (CryptoTestFailedException $ex) {
             throw new CException('Encryption key generation failed');
         } catch (CannotPerformOperationException $ex) {
             throw new CException('Encryption key generation failed');
         }
         $config = new Configuration();
         $config->attributes = array('key' => 'encryptionkey', 'value' => bin2hex($key));
         if (!$config->save()) {
             throw new CException('Encryption key generation failed');
         }
     }
     return hex2bin(self::getConfig('encryptionKey', NULL, 'settings_', true));
 }
开发者ID:charlesportwoodii,项目名称:cii,代码行数:23,代码来源:Cii.php

示例6: generateKey

 /**
  * Generate new random encryption key (binary format).
  *
  * @return string
  */
 public function generateKey()
 {
     return \Crypto::CreateNewRandomKey();
 }
开发者ID:spiral,项目名称:components,代码行数:9,代码来源:EncrypterManager.php

示例7: generateKey

 /**
  * Method to generate a new encryption key object.
  *
  * @param   array  $options  Key generation options.
  *
  * @return  JCryptKey
  *
  * @since   3.5
  * @throws  RuntimeException
  */
 public function generateKey(array $options = array())
 {
     // Create the new encryption key object.
     $key = new JCryptKey('crypto');
     // Generate the encryption key.
     try {
         $key->public = Crypto::CreateNewRandomKey();
     } catch (CryptoTestFailedException $ex) {
         throw new RuntimeException('Cannot safely create a key', $ex->getCode(), $ex);
     } catch (CannotPerformOperationException $ex) {
         throw new RuntimeException('Cannot safely create a key', $ex->getCode(), $ex);
     }
     // Explicitly flag the private as unused in this cipher.
     $key->private = 'unused';
     return $key;
 }
开发者ID:SysBind,项目名称:joomla-cms,代码行数:26,代码来源:crypto.php


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