public static IDStorage decryptKeyStoreStorage(byte[] c_baKey, byte[] c_baIV, string c_sBase64JsonStorage)
{
const int MacBitSize = 128;
byte [] baPayload = new byte[0];
var decryptCipher = new GcmBlockCipher(new AesFastEngine());
var parameters = new AeadParameters(new KeyParameter(c_baKey), MacBitSize, c_baIV, baPayload);
decryptCipher.Init (false, parameters);
byte[] baEncryptedStorage = Convert.FromBase64String (c_sBase64JsonStorage);
var decryptedText = new byte[decryptCipher.GetOutputSize(baEncryptedStorage.Length)];
try
{
var len = decryptCipher.ProcessBytes(baEncryptedStorage, 0, baEncryptedStorage.Length, decryptedText, 0);
decryptCipher.DoFinal(decryptedText, len);
}
catch (InvalidCipherTextException)
{
//Return null if it doesn't authenticate
return null;
}
string sJsonStorage = Encoding.GetEncoding (1252).GetString (decryptedText);
IDStorage _KeyStoreStorage = JsonConvert.DeserializeObject <IDStorage> (sJsonStorage);
return _KeyStoreStorage;
}