// Coerce key and iv into legal format for specificed algorithm then decrypt private static byte[] LegalKeyDecrypt(SymmetricAlgorithm algorithm, byte[] data, int startIndex, int length, byte[] key, byte[] iv) { byte[] rgbKey = algorithm.GetLegalKey(key); byte[] rgbIV = algorithm.GetLegalIV(iv); return algorithm.Decrypt(data, startIndex, length, rgbKey, rgbIV); }