Secret Class
Definition
- Namespace
- Codebelt.SharedKernel.Security
- Assemblies
- Codebelt.SharedKernel.dll
Represents a Secret object that can be used for storing sensitive data.
public record Secret : Token, IEquatable<ValueObject>, IEquatable<SingleValueObject<string>>, IEquatable<Token>, IEquatable<Secret>
- Inheritance
-
objectSecret
- Implements
- Inherited Members
-
SingleValueObject<string>.GetHashCode()SingleValueObject<string>.Equals(object)SingleValueObject<string>.Equals(ValueObject)SingleValueObject<string>.Equals(SingleValueObject<string>)SingleValueObject<string>.<Clone>$()SingleValueObject<string>.EqualityContract
Examples
The following example constructs a Secret from a 32-character hex string and converts it to its UTF-8 byte representation so it can be fed to a downstream cryptographic operation. Use the implicit Guid conversion when an upstream system hands you a request id, or the implicit string conversion when the secret arrives as a header value.
using System;
using System.Security.Cryptography;
using Codebelt.SharedKernel.Security;
namespace CryptographySample;
public static class KeyDerivation
{
public static byte[] DeriveHmacKey(string hexSecret)
{
var secret = new Secret(hexSecret);
var keyMaterial = secret.ToByteArray();
// The byte array is suitable as input for HMAC-SHA256 key derivation.
return SHA256.HashData(keyMaterial);
}
}
Remarks
Constructors
| Name | Description |
|---|---|
| Secret(Guid) | Initializes a new instance of the Secret class. |
| Secret(string) | Initializes a new instance of the Secret class. |
Methods
| Name | Description |
|---|---|
| ToByteArray(Action<EncodingOptions>) | Converts this instance to its equivalent byte[] representation. |
| ToString() | Returns a string> that represents this instance. |
Operators
| Name | Description |
|---|---|
| implicit operator Secret(Guid) | |
| implicit operator Secret(string) |