| | | 1 | | using System.Security.Cryptography; |
| | | 2 | | using Elsa.Identity.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Identity.Contracts; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Represents a secret hasher. |
| | | 8 | | /// </summary> |
| | | 9 | | public interface ISecretHasher |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Hashes the secret. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <param name="secret">The secret to hash.</param> |
| | | 15 | | /// <returns>The hashed secret.</returns> |
| | | 16 | | HashedSecret HashSecret(string secret); |
| | | 17 | | |
| | | 18 | | /// <summary> |
| | | 19 | | /// Hashes the secret. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <param name="secret">The secret to hash.</param> |
| | | 22 | | /// <param name="salt">The salt to use.</param> |
| | | 23 | | /// <returns>The hashed secret.</returns> |
| | | 24 | | HashedSecret HashSecret(string secret, byte[] salt); |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Hashes the secret. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <param name="secret">The secret to hash.</param> |
| | | 30 | | /// <param name="salt">The salt to use.</param> |
| | | 31 | | /// <returns>The hashed secret.</returns> |
| | | 32 | | byte[] HashSecret(byte[] secret, byte[] salt); |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Verifies the secret. |
| | | 36 | | /// </summary> |
| | | 37 | | /// <param name="clearTextSecret">The secret to verify.</param> |
| | | 38 | | /// <param name="secret">The hashed secret.</param> |
| | | 39 | | /// <param name="salt">The salt.</param> |
| | | 40 | | /// <returns>True if the secret is valid, otherwise false.</returns> |
| | | 41 | | bool VerifySecret(string clearTextSecret, string secret, string salt); |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Verifies the secret. |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="clearTextSecret">The secret to verify.</param> |
| | | 47 | | /// <param name="hashedSecret">The hashed secret.</param> |
| | | 48 | | /// <returns>True if the secret is valid, otherwise false.</returns> |
| | | 49 | | bool VerifySecret(string clearTextSecret, HashedSecret hashedSecret); |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Generates a salt. |
| | | 53 | | /// </summary> |
| | | 54 | | /// <param name="saltSize">The size of the salt.</param> |
| | | 55 | | /// <returns>The salt.</returns> |
| | 0 | 56 | | byte[] GenerateSalt(int saltSize = 32) => RandomNumberGenerator.GetBytes(saltSize); |
| | | 57 | | } |