Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4545582
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:50:02+00:00 2026-05-21T15:50:02+00:00

When I execute following code: const int blockSize = 64; const int keySize =

  • 0

When I execute following code:

        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);

…I get following exception:

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)
       ...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T15:50:02+00:00Added an answer on May 21, 2026 at 3:50 pm

    Already resolved problem. In new CfbBlockCipher(new Gost28147Engine(), subblockLength)) size of block should be passed as number of bits, not bytes. IV should be the same size as size of block passed to constructor of CfbBlockCipher so code have look like that:
    byte[] iv = new byte[subblockLength]

    A look into CfbBlockCipher.Init, exception is easy to track from here:

    /**
    * Initialise the cipher and, possibly, the initialisation vector (IV).
    * If an IV isn't passed as part of the parameter, the IV will be all zeros.
    * An IV which is too short is handled in FIPS compliant fashion.
    *
    * @param forEncryption if true the cipher is initialised for
    *  encryption, if false for decryption.
    * @param param the key and other data required by the cipher.
    * @exception ArgumentException if the parameters argument is
    * inappropriate.
    */
    public void Init(
        bool forEncryption,
        ICipherParameters parameters)
    {
        this.encrypting = forEncryption;
        if (parameters is ParametersWithIV)
        {
            ParametersWithIV ivParam = (ParametersWithIV) parameters;
            byte[] iv = ivParam.GetIV();
            int diff = IV.Length - iv.Length;
            Array.Copy(iv, 0, IV, diff, iv.Length);
            Array.Clear(IV, 0, diff);
    
            parameters = ivParam.Parameters;
        }
        Reset();
        cipher.Init(true, parameters);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the following code to execute a query in Lucene.Net var collector =
When I execute the following process-spawning code with a valid command string, I get
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
How do I execute the following shell command using the Python subprocess module? echo
If using code like the following to impersonate another user, [DllImport(advapi32.dll, SetLastError = true)]
I'm using the following code (from MSDN) to rename a C++ thread: #include <windows.h>
It is possible to execute the following code from multiple threads simultaneously. this._sequencer.Completed +=
I am trying to execute the following code. The code tries to parallely download
How exactly does fork() work? The following code #include <stdio.h> int main (int argc,
the following code: /***************************************************************************/ boost::mutex m; struct func { func(int v):n(v) {} void operator()()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.