public abstract class Mac extends Object:
Abstract base class for keyed message authentication codes.
The primary public HMAC API is exposed through Hmac, which binds the MAC to a concrete hash algorithm such as SHA256() or SHA3_512().
import klyn.cryptography
mac as Mac = Hmac(SHA256())
mac.init("secret")
print(mac.doFinal("hello").hex)| Modifier and Type | Member | Description |
|---|---|---|
| public readonly | algorithmalgorithm as String |
Canonical MAC algorithm name. |
| public readonly | hashAlgorithmhashAlgorithm as String |
Canonical digest algorithm name used by this MAC. |
| Modifier and Type | Member | Description |
|---|---|---|
| public | doFinaldoFinal(text as String = null) as Digest throws CryptoException: |
Computes the MAC for the buffered text and an optional final chunk. |
| public static | getInstancegetInstance(algorithm as String) as Mac throws CryptoException: |
Compatibility factory for dynamic algorithm selection. |
| public | init | Loads the secret key used to compute the MAC. |
| public | resetreset() as Void: |
Clears the buffered text accumulated with `update`. |
| public override | toStringtoString() as String: |
No summary. |
| public | update | Appends text to the in-memory MAC buffer. |
| public | verifyverify(text as String, expected as String, expectedEncoding as String = "hex") as Boolean throws CryptoException: |
Verifies a MAC value against the provided message. |