mirror of
https://github.com/bitwarden/mobile
synced 2026-02-19 02:43:29 +00:00
Add HashPurpose parameter to HashPasswordAsync
This commit is contained in:
@@ -31,7 +31,7 @@ namespace Bit.Core.Abstractions
|
||||
Task<byte[]> GetPrivateKeyAsync();
|
||||
Task<byte[]> GetPublicKeyAsync();
|
||||
Task<bool> HasEncKeyAsync();
|
||||
Task<string> HashPasswordAsync(string password, SymmetricCryptoKey key);
|
||||
Task<string> HashPasswordAsync(string password, SymmetricCryptoKey key, HashPurpose? hashPurpose);
|
||||
Task<bool> HasKeyAsync();
|
||||
Task<Tuple<SymmetricCryptoKey, EncString>> MakeEncKeyAsync(SymmetricCryptoKey key);
|
||||
Task<SymmetricCryptoKey> MakeKeyAsync(string password, string salt, KdfType? kdf, int? kdfIterations);
|
||||
|
||||
8
src/Core/Enums/HashPurpose.cs
Normal file
8
src/Core/Enums/HashPurpose.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace Bit.Core.Enums
|
||||
{
|
||||
public enum HashPurpose : byte
|
||||
{
|
||||
ServerAuthorization = 1,
|
||||
LocalAuthorization = 2,
|
||||
}
|
||||
}
|
||||
@@ -433,7 +433,7 @@ namespace Bit.Core.Services
|
||||
return new SymmetricCryptoKey(sendKey);
|
||||
}
|
||||
|
||||
public async Task<string> HashPasswordAsync(string password, SymmetricCryptoKey key)
|
||||
public async Task<string> HashPasswordAsync(string password, SymmetricCryptoKey key, HashPurpose? hashPurpose)
|
||||
{
|
||||
if (key == null)
|
||||
{
|
||||
@@ -443,7 +443,8 @@ namespace Bit.Core.Services
|
||||
{
|
||||
throw new Exception("Invalid parameters.");
|
||||
}
|
||||
var hash = await _cryptoFunctionService.Pbkdf2Async(key.Key, password, CryptoHashAlgorithm.Sha256, 1);
|
||||
var iterations = hashPurpose == HashPurpose.LocalAuthorization ? 2 : 1;
|
||||
var hash = await _cryptoFunctionService.Pbkdf2Async(key.Key, password, CryptoHashAlgorithm.Sha256, iterations);
|
||||
return Convert.ToBase64String(hash);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user