public static Int32? DecryptInt32(String data, Byte[] key, Byte[] ivec)
{
Int32? retVal = null;
String newData = data;
ASCIIEncoding encoder = new ASCIIEncoding();
AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
aesProvider.BlockSize = 128;
aesProvider.KeySize = 256;
ICryptoTransform cryptoTransform = aesProvider.CreateDecryptor(key, ivec);
MemoryStream decryptedStream = new MemoryStream();
try
{
byte[] inputInBytes = Base64PlusStringDecodeToBytes(newData);
CryptoStream cryptStream = new CryptoStream(decryptedStream, cryptoTransform, CryptoStreamMode.Write);
cryptStream.Write(inputInBytes, 0, inputInBytes.Length);
cryptStream.FlushFinalBlock();
decryptedStream.Position = 0;
byte[] result = new byte[decryptedStream.Length];
decryptedStream.Read(result, 0, Convert.ToInt32(decryptedStream.Length));
cryptStream.Close();
try
{
retVal = BitConverter.ToInt32(result, 0);
}
catch
{
retVal = null;
}
}
catch
{
retVal = null;
}
return retVal;
}