# Class KeyHelper Namespace: [CapyKit.Helpers](CapyKit.Helpers.md) Assembly: CapyKit.dll A class that contains methods for managing key creation and validation against a master key. ```csharp public class KeyHelper ``` #### Inheritance [object](https://learn.microsoft.com/dotnet/api/system.object) ← [KeyHelper](CapyKit.Helpers.KeyHelper.md) #### Inherited Members [object.Equals\(object?\)](https://learn.microsoft.com/dotnet/api/system.object.equals\#system\-object\-equals\(system\-object\)), [object.Equals\(object?, object?\)](https://learn.microsoft.com/dotnet/api/system.object.equals\#system\-object\-equals\(system\-object\-system\-object\)), [object.GetHashCode\(\)](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType\(\)](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone\(\)](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals\(object?, object?\)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString\(\)](https://learn.microsoft.com/dotnet/api/system.object.tostring) #### Extension Methods [ObjectExtensions.UpdateProperties\(KeyHelper, KeyHelper\)](CapyKit.Extensions.ObjectExtensions.md\#CapyKit\_Extensions\_ObjectExtensions\_UpdateProperties\_\_1\_\_\_0\_\_\_0\_), [ObjectExtensions.UpdateProperties\(object, object\)](CapyKit.Extensions.ObjectExtensions.md\#CapyKit\_Extensions\_ObjectExtensions\_UpdateProperties\_System\_Object\_System\_Object\_) ## Methods ### GenerateKey\(\) Generates a random key. ```csharp public string GenerateKey() ``` #### Returns [string](https://learn.microsoft.com/dotnet/api/system.string) The key. ### GetMasterKey\(\) Gets the master key. ```csharp public byte[] GetMasterKey() ``` #### Returns [byte](https://learn.microsoft.com/dotnet/api/system.byte)\[\] An array of byte. #### Exceptions [InvalidOperationException](https://learn.microsoft.com/dotnet/api/system.invalidoperationexception) Thrown when the requested operation is invalid. ### GetNumParts\(\) Gets the number parts. ```csharp public int GetNumParts() ``` #### Returns [int](https://learn.microsoft.com/dotnet/api/system.int32) The number parts. #### Exceptions [ArgumentException](https://learn.microsoft.com/dotnet/api/system.argumentexception) Thrown when one or more arguments have unsupported or illegal values. ### GetSaltSize\(\) Gets the salt size. ```csharp public int GetSaltSize() ``` #### Returns [int](https://learn.microsoft.com/dotnet/api/system.int32) The salt size. ### SetMasterKeyAccessor\(Func\) Sets the master key. ```csharp public void SetMasterKeyAccessor(Func accessor) ``` #### Parameters `accessor` [Func](https://learn.microsoft.com/dotnet/api/system.func\-1)<[byte](https://learn.microsoft.com/dotnet/api/system.byte)\[\]\> The accessor function. ### SetNumPartsAccessor\(Func\) Set and get the number of parts for the formatted key. Default is 2. ```csharp public void SetNumPartsAccessor(Func accessor) ``` #### Parameters `accessor` [Func](https://learn.microsoft.com/dotnet/api/system.func\-1)<[int](https://learn.microsoft.com/dotnet/api/system.int32)\> The accessor function. ### SetSaltSizeAccessor\(Func\) Sets the salt size (in bytes). Default is 4. ```csharp public void SetSaltSizeAccessor(Func accessor) ``` #### Parameters `accessor` [Func](https://learn.microsoft.com/dotnet/api/system.func\-1)<[int](https://learn.microsoft.com/dotnet/api/system.int32)\> The accessor function. ### ValidateKey\(string\) Validates the provided key. ```csharp public bool ValidateKey(string providedKey) ``` #### Parameters `providedKey` [string](https://learn.microsoft.com/dotnet/api/system.string) The provided key. #### Returns [bool](https://learn.microsoft.com/dotnet/api/system.boolean) True if it succeeds, false if it fails. #### See Also [KeyHelper](CapyKit.Helpers.KeyHelper.md).[GetMasterKey](CapyKit.Helpers.KeyHelper.md\#CapyKit\_Helpers\_KeyHelper\_GetMasterKey)\(\), [KeyHelper](CapyKit.Helpers.KeyHelper.md).[SetMasterKeyAccessor](CapyKit.Helpers.KeyHelper.md\#CapyKit\_Helpers\_KeyHelper\_SetMasterKeyAccessor\_System\_Func\_System\_Byte\_\_\_\_)\([Func](https://learn.microsoft.com/dotnet/api/system.func\-1)<[byte](https://learn.microsoft.com/dotnet/api/system.byte)\[\]\>\), [KeyHelper](CapyKit.Helpers.KeyHelper.md).masterKeyAccessor