From 5ba3fac0c0fb7d9563288fc690bc4bc517cd4d59 Mon Sep 17 00:00:00 2001 From: Jacob Fink Date: Tue, 18 Jul 2023 10:17:47 -0400 Subject: [PATCH] [PM-2713] add make user key method to crypto service --- src/Core/Abstractions/ICryptoService.cs | 1 + src/Core/Services/CryptoService.cs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/Core/Abstractions/ICryptoService.cs b/src/Core/Abstractions/ICryptoService.cs index 4bebc3ea9..529e6e835 100644 --- a/src/Core/Abstractions/ICryptoService.cs +++ b/src/Core/Abstractions/ICryptoService.cs @@ -12,6 +12,7 @@ namespace Bit.Core.Abstractions Task SetUserKeyAsync(UserKey userKey); Task GetUserKeyAsync(string userId = null); Task HasUserKeyAsync(string userId = null); + Task MakeUserKeyAsync(); Task ClearUserKeyAsync(string userId = null); Task SetMasterKeyEncryptedUserKeyAsync(string value, string userId = null); Task SetMasterKeyAsync(MasterKey masterKey, string userId = null); diff --git a/src/Core/Services/CryptoService.cs b/src/Core/Services/CryptoService.cs index fcd15b367..50a50b48d 100644 --- a/src/Core/Services/CryptoService.cs +++ b/src/Core/Services/CryptoService.cs @@ -51,6 +51,11 @@ namespace Bit.Core.Services return await GetUserKeyAsync(userId) != null; } + public async Task MakeUserKeyAsync() + { + return new UserKey(await _cryptoFunctionService.RandomBytesAsync(64)); + } + public async Task ClearUserKeyAsync(string userId = null) { await _stateService.SetUserKeyAsync(null, userId);