vault unlocking WIP

This commit is contained in:
TheXamlGuy
2024-05-03 19:33:32 +01:00
parent b17be4b0b8
commit e8b9eb7ae5
17 changed files with 102 additions and 43 deletions
+13 -3
View File
@@ -8,15 +8,25 @@ public class VaultKeyFactory(IKeyGenerator generator,
IDecryptor decryptor) :
IVaultKeyFactory
{
public VaultKey Create(byte[] phrase,
public VaultKey? Create(byte[] phrase,
byte[]? encryptedKey = null,
byte[]? salt = null)
{
salt ??= generator.Generate(16);
byte[] derivedKey = deriver.DeriveKey(phrase, salt);
encryptedKey ??= encryptor.Encrypt(generator.Generate(32), derivedKey);
byte[] decryptedKey = decryptor.Decrypt(encryptedKey, derivedKey);
if (encryptedKey is null)
{
if (!encryptor.TryEncrypt(generator.Generate(32), derivedKey, out encryptedKey) || encryptedKey is null)
{
return default;
}
}
if (!decryptor.TryDecrypt(encryptedKey, derivedKey, out byte[]? decryptedKey) || decryptedKey is null)
{
return default;
}
return new VaultKey(salt, encryptedKey, decryptedKey);
}