本文整理汇总了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);
}