本文整理匯總了PHP中Crypt_AES::enableContinuousBuffer方法的典型用法代碼示例。如果您正苦於以下問題:PHP Crypt_AES::enableContinuousBuffer方法的具體用法?PHP Crypt_AES::enableContinuousBuffer怎麽用?PHP Crypt_AES::enableContinuousBuffer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Crypt_AES
的用法示例。
在下文中一共展示了Crypt_AES::enableContinuousBuffer方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: 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);
}
示例2: 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);
}