From 635b09de9b6703d950d6a971d5696e2903a7882c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 11 Jul 2016 20:14:24 -0400 Subject: [PATCH] move CbcBlockCipher into crypto methods instead of singleton instance to avoid multithreaded issues --- src/App/Services/CryptoService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/App/Services/CryptoService.cs b/src/App/Services/CryptoService.cs index 1d5a53841..8c62b6366 100644 --- a/src/App/Services/CryptoService.cs +++ b/src/App/Services/CryptoService.cs @@ -22,12 +22,10 @@ namespace Bit.App.Services private readonly Random _random = new Random(); private readonly ISecureStorageService _secureStorage; - private readonly CbcBlockCipher _aesBlockCipher; private KeyParameter _keyParameter; public CryptoService(ISecureStorageService secureStorage) { - _aesBlockCipher = new CbcBlockCipher(new AesEngine()); _secureStorage = secureStorage; } @@ -93,7 +91,8 @@ namespace Bit.App.Services var iv = GenerateRandomInitializationVector(); var keyParamWithIV = new ParametersWithIV(_keyParameter, iv, 0, InitializationVectorSize); - var cipher = new PaddedBufferedBlockCipher(_aesBlockCipher); + var aesBlockCipher = new CbcBlockCipher(new AesEngine()); + var cipher = new PaddedBufferedBlockCipher(aesBlockCipher); cipher.Init(true, keyParamWithIV); var encryptedBytes = new byte[cipher.GetOutputSize(plaintextBytes.Length)]; var length = cipher.ProcessBytes(plaintextBytes, encryptedBytes, 0); @@ -117,7 +116,8 @@ namespace Bit.App.Services try { var keyParamWithIV = new ParametersWithIV(_keyParameter, encyptedValue.InitializationVectorBytes, 0, InitializationVectorSize); - var cipher = new PaddedBufferedBlockCipher(_aesBlockCipher); + var aesBlockCipher = new CbcBlockCipher(new AesEngine()); + var cipher = new PaddedBufferedBlockCipher(aesBlockCipher); cipher.Init(false, keyParamWithIV); byte[] comparisonBytes = new byte[cipher.GetOutputSize(encyptedValue.CipherTextBytes.Length)]; var length = cipher.ProcessBytes(encyptedValue.CipherTextBytes, comparisonBytes, 0);