mirror of
https://github.com/bitwarden/mobile
synced 2025-01-23 07:03:17 +01:00
move CbcBlockCipher into crypto methods instead of singleton instance to avoid multithreaded issues
This commit is contained in:
parent
f0455aad74
commit
635b09de9b
@ -22,12 +22,10 @@ namespace Bit.App.Services
|
|||||||
|
|
||||||
private readonly Random _random = new Random();
|
private readonly Random _random = new Random();
|
||||||
private readonly ISecureStorageService _secureStorage;
|
private readonly ISecureStorageService _secureStorage;
|
||||||
private readonly CbcBlockCipher _aesBlockCipher;
|
|
||||||
private KeyParameter _keyParameter;
|
private KeyParameter _keyParameter;
|
||||||
|
|
||||||
public CryptoService(ISecureStorageService secureStorage)
|
public CryptoService(ISecureStorageService secureStorage)
|
||||||
{
|
{
|
||||||
_aesBlockCipher = new CbcBlockCipher(new AesEngine());
|
|
||||||
_secureStorage = secureStorage;
|
_secureStorage = secureStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +91,8 @@ namespace Bit.App.Services
|
|||||||
var iv = GenerateRandomInitializationVector();
|
var iv = GenerateRandomInitializationVector();
|
||||||
var keyParamWithIV = new ParametersWithIV(_keyParameter, iv, 0, InitializationVectorSize);
|
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);
|
cipher.Init(true, keyParamWithIV);
|
||||||
var encryptedBytes = new byte[cipher.GetOutputSize(plaintextBytes.Length)];
|
var encryptedBytes = new byte[cipher.GetOutputSize(plaintextBytes.Length)];
|
||||||
var length = cipher.ProcessBytes(plaintextBytes, encryptedBytes, 0);
|
var length = cipher.ProcessBytes(plaintextBytes, encryptedBytes, 0);
|
||||||
@ -117,7 +116,8 @@ namespace Bit.App.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var keyParamWithIV = new ParametersWithIV(_keyParameter, encyptedValue.InitializationVectorBytes, 0, InitializationVectorSize);
|
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);
|
cipher.Init(false, keyParamWithIV);
|
||||||
byte[] comparisonBytes = new byte[cipher.GetOutputSize(encyptedValue.CipherTextBytes.Length)];
|
byte[] comparisonBytes = new byte[cipher.GetOutputSize(encyptedValue.CipherTextBytes.Length)];
|
||||||
var length = cipher.ProcessBytes(encyptedValue.CipherTextBytes, comparisonBytes, 0);
|
var length = cipher.ProcessBytes(encyptedValue.CipherTextBytes, comparisonBytes, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user