From 7b0bbfc3aaae2fc9c147fed99b22a30ffdf002f4 Mon Sep 17 00:00:00 2001 From: Thomas Rittson <31796059+eliykat@users.noreply.github.com> Date: Wed, 25 May 2022 18:51:45 +1000 Subject: [PATCH] [EC-178] Fix RSA encrypt for newSymmetricKey, add null check (#17) * Throw error if encKey is null * Fix variable name --- src/KeyConnector/Services/CryptoService.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/KeyConnector/Services/CryptoService.cs b/src/KeyConnector/Services/CryptoService.cs index 7c843e8..35367cb 100644 --- a/src/KeyConnector/Services/CryptoService.cs +++ b/src/KeyConnector/Services/CryptoService.cs @@ -108,7 +108,13 @@ namespace Bit.KeyConnector.Services else { var newSymmetricKey = await _cryptoFunctionService.GetRandomBytesAsync(32); - var decodedEncKey = await RsaEncryptAsync(_symmetricKey); + var decodedEncKey = await RsaEncryptAsync(newSymmetricKey); + + if (decodedEncKey == null) + { + throw new Exception("RSA encryption failed. Your RSA key may not be configured properly."); + } + encKey = Convert.ToBase64String(decodedEncKey); await _applicationDataRepository.UpdateSymmetricKeyAsync(encKey);