protected function _calculateDigest($digestAlgorithm, $data)
{
switch ($digestAlgorithm) {
case self::SHA1:
$alg = 'sha1';
break;
case self::SHA256:
$alg = 'sha256';
break;
case self::SHA512:
$alg = 'sha512';
break;
case self::RIPEMD160:
$alg = 'ripemd160';
break;
default:
throw new \Exception("Cannot validate digest: Unsupported Algorith <{$digestAlgorithm}>");
}
if (function_exists('hash')) {
return base64_encode(hash($alg, $data, true));
} elseif (function_exists('mhash')) {
$alg = "MHASH_" . strtoupper($alg);
return base64_encode(mhash(constant($alg), $data));
} elseif ($alg === 'sha1') {
return base64_encode(sha1($data, true));
} else {
throw new \Exception('SoapClient is unable to calculate a digest. Maybe you need the mhash library?');
}
}