-
Notifications
You must be signed in to change notification settings - Fork 20
Using MACs
To use a MAC you can use the following code:
var key = new Uint8List.fromList(
[0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF]
);
var params = new KeyParameter( key );
var mac = new Mac( "SHA-1/HMAC" )
..init( params )
;
var data = inputData();
var macValue = mac.update( data );
outputDigestValue( macValue );
In general, you construct the Mac with the factory constructor which receives the standard algorithm name and then init()
the MAC with its corresponding CipherParameters. See Algorithm nomenclature for documentation on standard algorithm names.
The type of CipherParameters to be used depends on the algorithm. For the example (HMAC) it consists of the secret key but,
for other algorithms, it can change. See the Table of provided algorithms to get information on which CipherParameters to
use for the algorithm of your choice.
To authenticate data you make successive calls to update() with the plain text buffer, the offset and the length to read. Finally, when you have exhausted all data, you call doFinal() with the output buffer and the offset to write to.
To authenticate data you make a call to process() with the data and the digest of it is returned. Alternatively, if you want
more performance, you can make successive calls to update() with the data buffer, the offset and the length to read. Finally,
when you have exhausted all data, you call doFinal() with the output buffer and the offset to write to.
You can reset the MAC to its initial state with the reset() method.