I need to output the time taken for the encryption of aes and twofish algorithm on a plaintext in php
i cant find a method to do it.
I need to output the time taken for the encryption of aes and twofish algorithm on a plaintext in php
i cant find a method to do it.
 
    
    For example, you can do like this:
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;