Class HmacSecureHashAlgorithm1
- Namespace
- Cuemon.Security.Cryptography
- Assembly
- Cuemon.Security.Cryptography.dll
Provides a Hash-based Message Authentication Code (HMAC) by using the SHA1 hash function. This class cannot be inherited. Implements the KeyedCryptoHash<TAlgorithm>
public sealed class HmacSecureHashAlgorithm1 : KeyedCryptoHash<HMACSHA1>, IHash, IConfigurable<ConvertibleOptions>
- Inheritance
-
HmacSecureHashAlgorithm1
- Implements
- Inherited Members
Examples
The following example demonstrates how to compute an HMAC-SHA1 hash with
using System;
using System.Text;
using Cuemon.Security.Cryptography;
namespace MyApp.Examples;
public static class HmacSecureHashAlgorithm1Example
{
public static void Demonstrate()
{
var algorithm = new HmacSecureHashAlgorithm1(CreateSecret(), null);
var result = algorithm.ComputeHash(Encoding.UTF8.GetBytes("Authenticate this message"));
Console.WriteLine(result.GetBytes().Length);
Console.WriteLine(result.ToBase64String());
}
private static byte[] CreateSecret() => Encoding.UTF8.GetBytes("docs-secret-sha1");
}
Constructors
HmacSecureHashAlgorithm1(byte[], Action<ConvertibleOptions>)
Initializes a new instance of the HmacSecureHashAlgorithm1 class.
public HmacSecureHashAlgorithm1(byte[] secret, Action<ConvertibleOptions> setup)
Parameters
secretbyte[]The secret key for HmacSecureHashAlgorithm1 encryption. The key can be any length, but if it is more than 64 bytes long it will be hashed (using SHA-1) to derive a 64-byte key. Therefore, the recommended size of the secret key is 64 bytes.
setupAction<ConvertibleOptions>The ConvertibleOptions which need to be configured.
See Also
Hash<TOptions>