HMACContext

    Used to create an HMAC for a message using a key.

    The HMACContext class is useful for advanced HMAC use cases, such as streaming the message as it supports creating the message over time rather than providing it all at once.

    And in C# we can use the following.

    1. using System;
    2. using System.Diagnostics;
    3. public class CryptoNode : Node
    4. private HMACContext ctx = new HMACContext();
    5. {
    6. PoolByteArray key = String("supersecret").to_utf8();
    7. Error err = ctx.Start(HashingContext.HASH_SHA256, key);
    8. GD.Assert(err == OK);
    9. PoolByteArray msg1 = String("this is ").to_utf8();
    10. PoolByteArray msg2 = String("super duper secret").to_utf8();
    11. GD.Assert(err == OK);
    12. err = ctx.Update(msg2);
    13. GD.Assert(err == OK);
    14. PoolByteArray hmac = ctx.Finish();
    15. GD.Print(hmac.HexEncode());
    16. }
    • finish ( )

    Returns the resulting HMAC. If the HMAC failed, an empty PoolByteArray is returned.



    Updates the message to be HMACed. This can be called multiple times before is called to append data to the message, but cannot be called until start has been called.