mirror of
https://github.com/KeyKeeperApp/KeyKeeper.git
synced 2026-04-17 18:16:28 +03:00
make salt field optional in CompositeKey so it can be set later by the callee
This commit is contained in:
@@ -7,22 +7,39 @@ namespace KeyKeeper.PasswordStore.Crypto;
|
||||
public class CompositeKey
|
||||
{
|
||||
public string Password { get; }
|
||||
public byte[] Salt { get; }
|
||||
public byte[]? Salt
|
||||
{
|
||||
get { return salt; }
|
||||
set
|
||||
{
|
||||
if (salt == null)
|
||||
salt = value;
|
||||
}
|
||||
}
|
||||
|
||||
public CompositeKey(string password, byte[] salt)
|
||||
private byte[]? salt;
|
||||
|
||||
public bool CanComputeHash
|
||||
{
|
||||
get { return salt != null; }
|
||||
}
|
||||
|
||||
public CompositeKey(string password, byte[]? salt)
|
||||
{
|
||||
if (password == null)
|
||||
throw new ArgumentNullException("password");
|
||||
Password = password;
|
||||
|
||||
if (salt == null || salt.Length < FileFormatConstants.MIN_MASTER_SALT_LEN ||
|
||||
salt.Length > FileFormatConstants.MAX_MASTER_SALT_LEN)
|
||||
if (salt != null && (salt.Length < FileFormatConstants.MIN_MASTER_SALT_LEN ||
|
||||
salt.Length > FileFormatConstants.MAX_MASTER_SALT_LEN))
|
||||
throw new ArgumentException("salt");
|
||||
Salt = salt;
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public byte[] Hash()
|
||||
{
|
||||
if (!CanComputeHash)
|
||||
throw new InvalidOperationException("salt is not set");
|
||||
byte[] passwordBytes = Encoding.UTF8.GetBytes(Password);
|
||||
byte[] hashedString = new byte[passwordBytes.Length + Salt.Length * 2];
|
||||
Salt.CopyTo(hashedString, 0);
|
||||
|
||||
Reference in New Issue
Block a user