klyn.cryptography.Mac.verify
method
public verify(text as String, expected as String, expectedEncoding as String = "hex") as Boolean throws CryptoException:
Description

Verifies a MAC value against the provided message.

Parameters
ParameterDescription
textSource UTF-8 text.
expectedExpected MAC value.
expectedEncodingExpected encoding: hex or base64.
Returns

True when the MAC matches.

Throws
  • CryptoException when the key is missing or the operation fails.
Example
import klyn.cryptography

mac = Hmac(SHA256())
mac.init("secret")
digest = mac.doFinal("hello")
print(mac.verify("hello", digest.hex))