php中的加解密时间如何输出
How do you output the encryption and decryption time in php
我需要在php
中明文输出aes和twofish算法加密的时间
我找不到方法。
例如,您可以这样做:
function encrypt($plaintext, $password) {
$method = "AES-256-CBC";
$key = hash('sha256', $password, true);
$iv = openssl_random_pseudo_bytes(16);
$ciphertext = openssl_encrypt($plaintext, $method, $key, OPENSSL_RAW_DATA, $iv);
$hash = hash_hmac('sha256', $ciphertext . $iv, $key, true);
return $iv . $hash . $ciphertext;
}
$time = -microtime(true);
for ($i=0; $i < mt_rand(1,100); $i++) {
$ct = encrypt("here_string", "here_password");
}
$time += microtime(true);
echo "Time: ",sprintf('%f', $time),PHP_EOL;
我需要在php
中明文输出aes和twofish算法加密的时间我找不到方法。
例如,您可以这样做:
function encrypt($plaintext, $password) {
$method = "AES-256-CBC";
$key = hash('sha256', $password, true);
$iv = openssl_random_pseudo_bytes(16);
$ciphertext = openssl_encrypt($plaintext, $method, $key, OPENSSL_RAW_DATA, $iv);
$hash = hash_hmac('sha256', $ciphertext . $iv, $key, true);
return $iv . $hash . $ciphertext;
}
$time = -microtime(true);
for ($i=0; $i < mt_rand(1,100); $i++) {
$ct = encrypt("here_string", "here_password");
}
$time += microtime(true);
echo "Time: ",sprintf('%f', $time),PHP_EOL;