mirror of
https://github.com/bitwarden/mobile.git
synced 2024-12-30 17:38:11 +01:00
Fix wrong key when decrypting cipher with mac
This commit is contained in:
parent
0131031ac4
commit
a429dcf978
@ -125,11 +125,11 @@ namespace Bit.App.Services
|
|||||||
|
|
||||||
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
|
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
|
||||||
// TODO: Turn on whenever ready to support encrypt-then-mac
|
// TODO: Turn on whenever ready to support encrypt-then-mac
|
||||||
var cryptoKey = provider.CreateSymmetricKey(false ? EncKey : Key);
|
var cryptoKey = provider.CreateSymmetricKey(true ? EncKey : Key);
|
||||||
var iv = WinRTCrypto.CryptographicBuffer.GenerateRandom(provider.BlockLength);
|
var iv = WinRTCrypto.CryptographicBuffer.GenerateRandom(provider.BlockLength);
|
||||||
var encryptedBytes = WinRTCrypto.CryptographicEngine.Encrypt(cryptoKey, plaintextBytes, iv);
|
var encryptedBytes = WinRTCrypto.CryptographicEngine.Encrypt(cryptoKey, plaintextBytes, iv);
|
||||||
// TODO: Turn on whenever ready to support encrypt-then-mac
|
// TODO: Turn on whenever ready to support encrypt-then-mac
|
||||||
var mac = false ? ComputeMac(encryptedBytes, iv) : null;
|
var mac = true ? ComputeMac(encryptedBytes, iv) : null;
|
||||||
|
|
||||||
return new CipherString(Convert.ToBase64String(iv), Convert.ToBase64String(encryptedBytes), mac);
|
return new CipherString(Convert.ToBase64String(iv), Convert.ToBase64String(encryptedBytes), mac);
|
||||||
}
|
}
|
||||||
@ -158,7 +158,7 @@ namespace Bit.App.Services
|
|||||||
}
|
}
|
||||||
|
|
||||||
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
|
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
|
||||||
var cryptoKey = provider.CreateSymmetricKey(encyptedValue.Mac != null ? MacKey : Key);
|
var cryptoKey = provider.CreateSymmetricKey(encyptedValue.Mac != null ? EncKey : Key);
|
||||||
var decryptedBytes = WinRTCrypto.CryptographicEngine.Decrypt(cryptoKey, encyptedValue.CipherTextBytes,
|
var decryptedBytes = WinRTCrypto.CryptographicEngine.Decrypt(cryptoKey, encyptedValue.CipherTextBytes,
|
||||||
encyptedValue.InitializationVectorBytes);
|
encyptedValue.InitializationVectorBytes);
|
||||||
return Encoding.UTF8.GetString(decryptedBytes, 0, decryptedBytes.Length).TrimEnd('\0');
|
return Encoding.UTF8.GetString(decryptedBytes, 0, decryptedBytes.Length).TrimEnd('\0');
|
||||||
|
Loading…
Reference in New Issue
Block a user