本文整理汇总了PHP中Crypto::RuntimeTest方法的典型用法代码示例。如果您正苦于以下问题:PHP Crypto::RuntimeTest方法的具体用法?PHP Crypto::RuntimeTest怎么用?PHP Crypto::RuntimeTest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Crypto
的用法示例。
在下文中一共展示了Crypto::RuntimeTest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpBeforeClass
/**
* This method is called before the first test of this test class is run.
*
* @return void
*/
public static function setUpBeforeClass()
{
// Only run the test if the environment supports it.
try {
Crypto::RuntimeTest();
} catch (CryptoTestFailedException $e) {
self::markTestSkipped('The environment cannot safely perform encryption with this cipher.');
}
}
示例2: Decrypt
public static function Decrypt($ciphertext, $key)
{
Crypto::RuntimeTest();
// Extract the HMAC from the front of the ciphertext.
if (self::our_strlen($ciphertext) <= self::MAC_BYTE_SIZE) {
throw new InvalidCiphertextException();
}
$hmac = self::our_substr($ciphertext, 0, self::MAC_BYTE_SIZE);
if ($hmac === FALSE) {
throw new CannotPerformOperationException();
}
$ciphertext = self::our_substr($ciphertext, self::MAC_BYTE_SIZE);
if ($ciphertext === FALSE) {
throw new CannotPerformOperationException();
}
// Regenerate the same authentication sub-key.
$akey = self::HKDF(self::HASH_FUNCTION, $key, self::KEY_BYTE_SIZE, self::AUTHENTICATION_INFO);
if (self::VerifyHMAC($hmac, $ciphertext, $akey)) {
// Regenerate the same encryption sub-key.
$keysize = self::KEY_BYTE_SIZE;
$ekey = self::HKDF(self::HASH_FUNCTION, $key, $keysize, self::ENCRYPTION_INFO);
// Extract the initialization vector from the ciphertext.
self::EnsureFunctionExists("mcrypt_get_iv_size");
$ivsize = mcrypt_get_iv_size(self::CIPHER, self::CIPHER_MODE);
if ($ivsize === FALSE || $ivsize <= 0) {
throw new CannotPerformOperationException();
}
if (self::our_strlen($ciphertext) <= $ivsize) {
throw new InvalidCiphertextException();
}
$iv = self::our_substr($ciphertext, 0, $ivsize);
if ($iv === FALSE) {
throw new CannotPerformOperationException();
}
$ciphertext = self::our_substr($ciphertext, $ivsize);
if ($ciphertext === FALSE) {
throw new CannotPerformOperationException();
}
$plaintext = self::PlainDecrypt($ciphertext, $ekey, $iv);
return $plaintext;
} else {
/*
* We throw an exception instead of returning FALSE because we want
* a script that doesn't handle this condition to CRASH, instead
* of thinking the ciphertext decrypted to the value FALSE.
*/
throw new InvalidCiphertextException();
}
}
示例3: mb_internal_encoding
<?php
// Set the encoding to something more "challenging."
$ret = mb_internal_encoding('UTF-8');
if ($ret === FALSE) {
echo "Couldn't set encoding.";
exit(1);
}
// Dump out the settings / encoding for future reference.
$val = ini_get("mbstring.func_overload");
echo "Settings: \n";
echo " func_overload: " . $val . "\n";
echo " mb_internal_encoding(): " . mb_internal_encoding() . "\n";
// Perform the tests.
require_once 'Crypto.php';
try {
Crypto::RuntimeTest();
echo "TEST PASSED!\n";
exit(0);
} catch (CryptoTestFailedException $ex) {
echo "TEST FAILED!\n";
var_dump($ex);
exit(1);
} catch (CannotPerformOperationException $ex) {
echo "TEST FAILED\n";
var_dump($ex);
exit(1);
}