catch when key is null

This commit is contained in:
Kyle Spearrin 2016-08-06 03:10:54 -04:00
parent 33a01c0512
commit 8c8db7c34b
1 changed files with 12 additions and 10 deletions

View File

@ -5,6 +5,7 @@ using Bit.App.Abstractions;
using Bit.App.Models; using Bit.App.Models;
using PCLCrypto; using PCLCrypto;
using System.Linq; using System.Linq;
using Xamarin.Forms;
namespace Bit.App.Services namespace Bit.App.Services
{ {
@ -128,6 +129,8 @@ namespace Bit.App.Services
} }
public string Decrypt(CipherString encyptedValue) public string Decrypt(CipherString encyptedValue)
{
try
{ {
if(Key == null) if(Key == null)
{ {
@ -139,8 +142,7 @@ namespace Bit.App.Services
throw new ArgumentNullException(nameof(encyptedValue)); throw new ArgumentNullException(nameof(encyptedValue));
} }
try
{
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7); var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
var cryptoKey = provider.CreateSymmetricKey(Key); var cryptoKey = provider.CreateSymmetricKey(Key);
var decryptedBytes = WinRTCrypto.CryptographicEngine.Decrypt(cryptoKey, encyptedValue.CipherTextBytes, var decryptedBytes = WinRTCrypto.CryptographicEngine.Decrypt(cryptoKey, encyptedValue.CipherTextBytes,