Когда я выполняю следующий код:
const int blockSize = 64;
const int keySize = 256;
string inputText;
byte[] inputBytes;
using (StreamReader reader = new StreamReader(inputFile))
{
inputText = reader.ReadToEnd();
inputBytes = StringToBytes(inputText);
}
byte[] outputBytes = new byte[inputBytes.Length];
CipherKeyGenerator keygen = new CipherKeyGenerator();
SecureRandom rand = new SecureRandom();
KeyGenerationParameters keygenParams = new KeyGenerationParameters(rand, keySize);
keygen.Init(keygenParams);
byte[] key = keygen.GenerateKey();
BufferedBlockCipher cipher = null;
ICipherParameters cipherParams = null;
byte[] iv = new byte[blockSize];
rand.NextBytes(iv);
cipherParams = new ParametersWithIV(
new ParametersWithSBox(
new KeyParameter(key),
Gost28147Engine.GetSBox("E-A")),
iv);
cipher = new BufferedBlockCipher(
new CfbBlockCipher(new Gost28147Engine(), subblockLength));
cipher.Init(true, cipherParams);
int bytesLength = cipher.ProcessBytes(inputBytes, 0, inputBytes.Length, outputBytes, 0);
cipher.DoFinal(outputBytes, bytesLength);
... Я получаю следующее исключение:
System.ArgumentOutOfRangeException was unhandled
Source=mscorlib
ParamName=dstIndex
StackTrace:
w System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
w System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length)
w Org.BouncyCastle.Crypto.Modes.CfbBlockCipher.Init(Boolean forEncryption, ICipherParameters parameters)
w Org.BouncyCastle.Crypto.BufferedBlockCipher.Init(Boolean forEncryption, ICipherParameters parameters)
...