169 lines
4.9 KiB
Markdown
169 lines
4.9 KiB
Markdown
# <a id="CapyKit_Helpers_KeyHelper"></a> 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, 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
|
|
|
|
### <a id="CapyKit_Helpers_KeyHelper_GenerateKey"></a> GenerateKey\(\)
|
|
|
|
Generates a random key.
|
|
|
|
```csharp
|
|
public string GenerateKey()
|
|
```
|
|
|
|
#### Returns
|
|
|
|
[string](https://learn.microsoft.com/dotnet/api/system.string)
|
|
|
|
The key.
|
|
|
|
### <a id="CapyKit_Helpers_KeyHelper_GetMasterKey"></a> 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.
|
|
|
|
### <a id="CapyKit_Helpers_KeyHelper_GetNumParts"></a> 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.
|
|
|
|
### <a id="CapyKit_Helpers_KeyHelper_GetSaltSize"></a> GetSaltSize\(\)
|
|
|
|
Gets the salt size.
|
|
|
|
```csharp
|
|
public int GetSaltSize()
|
|
```
|
|
|
|
#### Returns
|
|
|
|
[int](https://learn.microsoft.com/dotnet/api/system.int32)
|
|
|
|
The salt size.
|
|
|
|
### <a id="CapyKit_Helpers_KeyHelper_SetMasterKeyAccessor_System_Func_System_Byte____"></a> SetMasterKeyAccessor\(Func<byte\[\]\>\)
|
|
|
|
Sets the master key.
|
|
|
|
```csharp
|
|
public void SetMasterKeyAccessor(Func<byte[]> 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.
|
|
|
|
### <a id="CapyKit_Helpers_KeyHelper_SetNumPartsAccessor_System_Func_System_Int32__"></a> SetNumPartsAccessor\(Func<int\>\)
|
|
|
|
Set and get the number of parts for the formatted key. Default is 2.
|
|
|
|
```csharp
|
|
public void SetNumPartsAccessor(Func<int> 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.
|
|
|
|
### <a id="CapyKit_Helpers_KeyHelper_SetSaltSizeAccessor_System_Func_System_Int32__"></a> SetSaltSizeAccessor\(Func<int\>\)
|
|
|
|
Sets the salt size (in bytes). Default is 4.
|
|
|
|
```csharp
|
|
public void SetSaltSizeAccessor(Func<int> 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.
|
|
|
|
### <a id="CapyKit_Helpers_KeyHelper_ValidateKey_System_String_"></a> 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
|
|
|