Add code for opening vault

This commit is contained in:
TheXamlGuy
2024-05-02 23:07:47 +01:00
parent c324cf9542
commit c1613d765c
11 changed files with 54 additions and 112 deletions
+8 -8
View File
@@ -8,17 +8,17 @@ public class VaultKeyFactory(IKeyGenerator generator,
IDecryptor decryptor) :
IVaultKeyFactory
{
public VaultKey Create(string password)
public VaultKey Create(byte[] phrase,
byte[]? encryptedKey = null,
byte[]? salt = null)
{
byte[] salt = generator.Generate(16);
byte[] key = generator.Generate(32);
salt ??= generator.Generate(16);
byte[] derivedKey = deriver.DeriveKey(phrase, salt);
byte[] derivedKey = deriver.DeriveKey(password, salt);
encryptedKey ??= encryptor.Encrypt(generator.Generate(32), derivedKey);
byte[] decryptedKey = decryptor.Decrypt(encryptedKey, derivedKey);
byte[] publicKey = encryptor.Encrypt(key, derivedKey);
byte[] privateKey = decryptor.Decrypt(publicKey, derivedKey);
return new VaultKey(salt, publicKey, privateKey);
return new VaultKey(salt, encryptedKey, decryptedKey);
}
}