Exemplo n.º 1
0
        /**
         * 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.
         *
         * @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 IllegalArgumentException if the params argument is
         * inappropriate.
         */
        public void init(
            bool encrypting,
            CipherParameters parameters)
        //throws IllegalArgumentException
        {
            this.encrypting = encrypting;

            if (typeof(ParametersWithIV).IsInstanceOfType(parameters))
            {
                ParametersWithIV ivParam = (ParametersWithIV)parameters;
                byte[]           iv      = ivParam.getIV();

                if (iv.Length != blockSize)
                {
                    throw new ArgumentException("initialisation vector must be the same length as block size");
                }

                Array.Copy(iv, 0, IV, 0, iv.Length);

                reset();

                cipher.init(encrypting, ivParam.getParameters());
            }
            else
            {
                reset();

                cipher.init(encrypting, parameters);
            }
        }
Exemplo n.º 2
0
        /**
         * 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 param the key and other data required by the cipher.
         * @exception ArgumentException if the params argument is
         * inappropriate.
         */
        public void init(
            CipherParameters parameters)
        //throws ArgumentException
        {
            //this.encrypting = true;

            if (typeof(ParametersWithIV).IsInstanceOfType(parameters))
            {
                ParametersWithIV ivParam = (ParametersWithIV)parameters;
                byte[]           iv      = ivParam.getIV();

                if (iv.Length < IV.Length)
                {
                    Array.Copy(iv, 0, IV, IV.Length - iv.Length, iv.Length);
                }
                else
                {
                    Array.Copy(iv, 0, IV, 0, IV.Length);
                }

                reset();

                cipher.init(true, ivParam.getParameters());
            }
            else
            {
                reset();

                cipher.init(true, parameters);
            }
        }
Exemplo n.º 3
0
        public void init(bool forEncryption, CipherParameters parameters)
        //throws IllegalArgumentException
        {
            this.encrypting = forEncryption;

            if (typeof(ParametersWithIV).IsInstanceOfType(parameters))
            {
                ParametersWithIV ivParam = (ParametersWithIV)parameters;
                byte[]           iv      = ivParam.getIV();
                Array.Copy(iv, 0, IV, 0, IV.Length);

                reset();
                cipher.init(true, ivParam.getParameters());
            }
        }
Exemplo n.º 4
0
        /**
         * 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 IllegalArgumentException if the params argument is
         * inappropriate.
         */
        public void init(
            bool encrypting,
            CipherParameters parameters)
        //throws ArgumentException
        {
            this.encrypting = encrypting;

            if (typeof(ParametersWithIV).IsInstanceOfType(parameters))
            {
                ParametersWithIV ivParam = (ParametersWithIV)parameters;
                byte[]           iv      = ivParam.getIV();

                if (iv.Length < IV.Length)
                {
                    // prepend the supplied IV with zeros (per FIPS PUB 81)
                    Array.Copy(iv, 0, IV, IV.Length - iv.Length, iv.Length);
                    for (int i = 0; i < IV.Length - iv.Length; i++)
                    {
                        IV[i] = 0;
                    }
                }
                else
                {
                    Array.Copy(iv, 0, IV, 0, IV.Length);
                }

                reset();

                cipher.init(true, ivParam.getParameters());
            }
            else
            {
                reset();

                cipher.init(true, parameters);
            }
        }