I have tested the code below and it seems to work for CBC and PKSC7 Padding and a key generator for the key and the IV.
FileStream varFileStreamInput, varFileStreamOutput;
Byte[] varInBuffer, varOutBuffer;
varInBuffer = new Byte[1000];
varOutBuffer = new Byte[1000];
Int32 varBytesRead;
PbeParametersGenerator varKeyGenerator = new Pkcs12ParametersGenerator(new Sha256Digest());
varKeyGenerator.Init(Encoding.ASCII.GetBytes(varPassword), Encoding.ASCII.GetBytes(varSalt), 10240);
ParametersWithIV varParmWithIV = (ParametersWithIV)varKeyGenerator.GenerateDerivedParameters("AES128", 128, 128);
Org.BouncyCastle.Crypto.BufferedBlockCipher varBufBlckCipher = new PaddedBufferedBlockCipher(new CbcBlockCipher(new AesEngine()), new Pkcs7Padding());
varBufBlckCipher.Init(true, varParmWithIV);
varFileStreamInput = new FileStream(@"C:\Temp12\Test1.txt", FileMode.Open);
varFileStreamOutput = new FileStream(@"C:\Temp12\Test3.txt.enc", FileMode.Create);
varBytesRead = 0;
while (varFileStreamInput.Position != varFileStreamInput.Length)
{
varBytesRead = varFileStreamInput.Read(varInBuffer, 0, 1000);
varOutBuffer = varBufBlckCipher.ProcessBytes(varInBuffer, 0, varBytesRead);
varFileStreamOutput.Write(varOutBuffer, 0, varOutBuffer.Length);
}
varOutBuffer = varBufBlckCipher.DoFinal();
varFileStreamOutput.Write(varOutBuffer, 0, varOutBuffer.Length);
varFileStreamOutput.Flush();
varFileStreamOutput.Close();
varFileStreamInput.Close();
varBufBlckCipher.Init(false, varParmWithIV);
varFileStreamInput = new FileStream(@"C:\Temp12\Test3.txt.enc", FileMode.Open);
varFileStreamOutput = new FileStream(@"C:\Temp12\Test3.txt.dec", FileMode.Create);
varBytesRead = 0;
while (varFileStreamInput.Position != varFileStreamInput.Length)
{
varBytesRead = varFileStreamInput.Read(varInBuffer, 0, 1000);
varOutBuffer = varBufBlckCipher.ProcessBytes(varInBuffer, 0, varBytesRead);
varFileStreamOutput.Write(varOutBuffer, 0, varOutBuffer.Length);
}
varOutBuffer = varBufBlckCipher.DoFinal();
varFileStreamOutput.Write(varOutBuffer, 0, varOutBuffer.Length);
varFileStreamOutput.Flush();
varFileStreamOutput.Close();
varFileStreamInput.Close();