Hmac
Calculates HMAC
Example:
import Md5 from "crypto-api/src/hasher/md5";
import Hmac from "crypto-api/src/mac/hmac";
import {toHex} from "crypto-api/src/encoder/hex";
let hasher = new Md5();
let hmac = new Hmac('key', hasher);
hmac.update('message');
console.log(toHex(hmac.finalize()));
import Md5 from "crypto-api/src/hasher/md5";
import Hmac from "crypto-api/src/mac/hmac";
import {toHex} from "crypto-api/src/encoder/hex";
import {fromUtf} from "crypto-api/src/encoder/utf";
let hasher = new Md5();
let hmac = new Hmac(fromUtf('key'), hasher);
hmac.update(fromUtf('message'));
console.log(toHex(hmac.finalize()));
<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
var hasher = CryptoApi.getHasher('md5');
var hmac = CryptoApi.getHmac('key', hasher);
hmac.update('message');
console.log(CryptoApi.encoder.toHex(hmac.finalize()));
</script>
<script src="https://nf404.github.io/crypto-api/crypto-api.min.js"></script>
<script>
var hasher = CryptoApi.getHasher('md5');
console.log(CryptoApi.hmac('key', 'message', hasher));
</script>
Constructor Summary
Public Constructor | ||
public |
constructor(key: string, hasher: Hasher) |
Method Summary
Public Methods | ||
public |
finalize(): string Finalize hmac and return result |
|
public |
update(message: string) Update message from binary string |