KeyedHashFactory Class
Definition
- Namespace
- Cuemon.Security.Cryptography
- Assemblies
- Cuemon.Security.Cryptography.dll
Provides access to factory methods for creating and configuring Hash instances based on KeyedCryptoHash<TAlgorithm>.
public static class KeyedHashFactory
- Inheritance
-
KeyedHashFactory
Examples
The following example shows how to compute an HMAC-SHA256 hash for message authentication using KeyedHashFactory. It creates a keyed hash algorithm with a secret key, hashes an input string, and prints the hexadecimal digest.
using System;
using System.Text;
using Cuemon.Security.Cryptography;
namespace Cuemon.Security.Cryptography;
public class KeyedHashFactoryExample
{
public void Demonstrate()
{
var secret = Encoding.UTF8.GetBytes("my-secret-key");
var hmac = KeyedHashFactory.CreateHmacCryptoSha256(secret);
var input = "Message to authenticate";
var hash = hmac.ComputeHash(Encoding.UTF8.GetBytes(input));
Console.WriteLine($"HMAC-SHA256: {BitConverter.ToString(hash.To<byte[]>(bytes => bytes)).Replace("-", "")}");
}
}
Methods
| Name | Description |
|---|---|
| CreateHmacCrypto(byte[], KeyedCryptoAlgorithm, Action<ConvertibleOptions>) | Creates an instance of a HMAC cryptographic implementation that derives from KeyedCryptoHash<TAlgorithm> with the specified |
| CreateHmacCryptoMd5(byte[], Action<ConvertibleOptions>) | Creates an instance of HmacMessageDigest5. |
| CreateHmacCryptoSha1(byte[], Action<ConvertibleOptions>) | Creates an instance of HmacSecureHashAlgorithm1. |
| CreateHmacCryptoSha256(byte[], Action<ConvertibleOptions>) | Creates an instance of HmacSecureHashAlgorithm256. |
| CreateHmacCryptoSha384(byte[], Action<ConvertibleOptions>) | Creates an instance of HmacSecureHashAlgorithm384. |
| CreateHmacCryptoSha512(byte[], Action<ConvertibleOptions>) | Creates an instance of HmacSecureHashAlgorithm512. |