<?php
function encrypt($texttocrypt, $ky, $iv)
{
// $ky = '5rrdv4lkjdshfkl43bgd'; // Key from file
// $iv = ;
try {
$encrypted = "";
$length = strlen($texttocrypt);
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
mcrypt_generic_init($cipher, $ky, $iv);
$encrypted = base64_encode(mcrypt_generic($cipher, $texttocrypt));
mcrypt_generic_deinit($cipher);
$result1 = bin2hex($iv);
$result2 = bin2hex($encrypted);
$result = $result1 . $result2;
return $result;
} catch (Exception $e) {
$this->lastError = "Error while encrypting '".$texttocrypt."' - ".$e->getMessage();
throw new Exception($this->lastError);
}
}
echo encrypt('HiOnoomyot9', 'jhfjdjj%6s77w', '234ghyjdGt57Bgsde764Lo905hvfDw20');
preferences:
55.54 ms | 402 KiB | 5 Q