2

In Java we have progressive hmac like so:

Mac mac = Mac.getInstance("HmacSHA256");
mac.init(macKey);
mac.update(part(0));
mac.update(part(1));
...
byte[] fullMac = mac.doFinal(part(n))

Please what is the c# equivalent for progressive HMACSHA256?

Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157

1 Answers1

5

Got it! Microsoft over-cooked the otherwise simple Update operation into TransformBlock & TransformFinalBlock

Mac mac = Mac.getInstance("HmacSHA256");
mac.init(macKey);
mac.update(part(0));
mac.update(part(1));
...
byte[] fullMac = mac.doFinal(part(9))

in .Net this now becomes (vb.net)

dim fullMac as byte()
using mac=New HMACSHA256(macKey)
   mac.TransformBlock(part(0),0,part(0).Length,null,0)
   mac.TransformBlock(part(1),0,part(1).Length,null,0)
   ...
   fullMac=mac.TransformFinalBlock(part(9),0,part(9).Length)
end using

I don't see how this helps developer-productivity in any way :(

Charles Okwuagwu
  • 10,538
  • 16
  • 87
  • 157