/// <summary>Signs a message with HMAC-SHA-256.</summary> /// <param name="message">The message.</param> /// <param name="key">The 32 byte key.</param> /// <returns>32 byte authentication code.</returns> /// <exception cref="KeyOutOfRangeException"></exception> public static byte[] SignHmacSha256(byte[] message, byte[] key) { //validate the length of the key if (key == null || key.Length != CRYPTO_AUTH_HMACSHA256_KEY_BYTES) { throw new KeyOutOfRangeException("key", (key == null) ? 0 : key.Length, string.Format("key must be {0} bytes in length.", CRYPTO_AUTH_HMACSHA256_KEY_BYTES)); } var buffer = new byte[CRYPTO_AUTH_HMACSHA256_BYTES]; SodiumLibrary.crypto_auth_hmacsha256(buffer, message, message.Length, key); return(buffer); }