/**
* Decrypt the given value.
*
* @param string $value
*
* @return string
*/
private function decrypt($value)
{
$this->checkKey();
$decoded = base64_decode($value);
$hmac = mb_substr($decoded, 0, 32, '8bit');
$iv = mb_substr($decoded, 32, 16, '8bit');
$cipher = mb_substr($decoded, 48, null, '8bit');
$calculated = hash_hmac('sha256', $iv . $cipher, $this->authentication, true);
if (Helpers::hashEquals($hmac, $calculated)) {
$value = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->key, $cipher, 'ctr', $iv), "");
return json_decode($value, true);
}
}