示例#1
0
        public void init(
            CipherParameters param)
        {
            AsymmetricKeyParameter kParam;

            if (typeof(ParametersWithRandom).IsInstanceOfType(param))
            {
                ParametersWithRandom rParam = (ParametersWithRandom)param;

                this.random = rParam.getRandom();
                kParam      = (AsymmetricKeyParameter)rParam.getParameters();
            }
            else
            {
                this.random = new SecureRandom();
                kParam      = (AsymmetricKeyParameter)param;
            }

            if (!(typeof(DHPrivateKeyParameters).IsInstanceOfType(kParam)))
            {
                throw new ArgumentException("DHEngine expects DHPrivateKeyParameters");
            }

            this.key      = (DHPrivateKeyParameters)kParam;
            this.dhParams = key.getParameters();
        }
示例#2
0
        public virtual void  init(bool forSigning, CipherParameters param)
        {
            RSAKeyParameters kParam = null;

            if (param is ParametersWithRandom)
            {
                ParametersWithRandom p = (ParametersWithRandom)param;

                kParam = (RSAKeyParameters)p.getParameters();
                random = p.getRandom();
            }
            else
            {
                kParam = (RSAKeyParameters)param;
                if (forSigning)
                {
                    random = new SecureRandom();
                }
            }

            cipher.init(forSigning, kParam);

            emBits = kParam.getModulus().bitLength() - 1;

            block = new byte[(emBits + 7) / 8];

            reset();
        }
示例#3
0
        /// <summary> Initialise the signer.
        ///
        /// </summary>
        /// <param name="forSigning">true if for signing, false if for verification.
        /// </param>
        /// <param name="param">parameters for signature generation/verification. If the
        /// parameters are for generation they should be a ParametersWithRandom,
        /// a ParametersWithSalt, or just an RSAKeyParameters object. If RSAKeyParameters
        /// are passed in a SecureRandom will be created.
        /// </param>
        /// <exception cref="ArgumentException"> IllegalArgumentException if wrong parameter type or a fixed
        /// salt is passed in which is the wrong length.
        /// </exception>
        public virtual void  init(bool forSigning, CipherParameters param)
        {
            RSAKeyParameters kParam = null;
            int lengthOfSalt        = saltLength;

            if (param is ParametersWithRandom)
            {
                ParametersWithRandom p = (ParametersWithRandom)param;

                kParam = (RSAKeyParameters)p.getParameters();
                random = p.getRandom();
            }
            else if (param is ParametersWithSalt)
            {
                ParametersWithSalt p = (ParametersWithSalt)param;

                kParam       = (RSAKeyParameters)p.getParameters();
                standardSalt = p.getSalt();
                lengthOfSalt = standardSalt.Length;
            }
            else
            {
                kParam = (RSAKeyParameters)param;
                if (forSigning)
                {
                    random = new SecureRandom();
                }
            }

            cipher.init(forSigning, kParam);

            keyBits = kParam.getModulus().bitLength();

            block = new byte[(keyBits + 7) / 8];

            if (trailer == TRAILER_IMPLICIT)
            {
                mBuf = new byte[block.Length - digest.getDigestSize() - lengthOfSalt - 1 - 1];
            }
            else
            {
                mBuf = new byte[block.Length - digest.getDigestSize() - lengthOfSalt - 1 - 2];
            }

            reset();
        }
示例#4
0
        /**
         * initialise the ElGamal engine.
         *
         * @param forEncryption true if we are encrypting, false otherwise.
         * @param param the necessary ElGamal key parameters.
         */
        public void init(
            bool forEncryption,
            CipherParameters param)
        {
            if (typeof(ParametersWithRandom).IsInstanceOfType(param))
            {
                ParametersWithRandom p = (ParametersWithRandom)param;

                this.key    = (ElGamalKeyParameters)p.getParameters();
                this.random = p.getRandom();
            }
            else
            {
                this.key    = (ElGamalKeyParameters)param;
                this.random = new SecureRandom();
            }

            this.forEncryption = forEncryption;
        }
示例#5
0
        public void init(
            bool forEncryption,
            CipherParameters param)
        {
            AsymmetricKeyParameter kParam;

            if (typeof(ParametersWithRandom).IsInstanceOfType(param))
            {
                ParametersWithRandom rParam = (ParametersWithRandom)param;

                this.random = rParam.getRandom();
                kParam      = (AsymmetricKeyParameter)rParam.getParameters();
            }
            else
            {
                this.random = new SecureRandom();
                kParam      = (AsymmetricKeyParameter)param;
            }

            engine.init(forEncryption, kParam);

            this.forEncryption = forEncryption;
        }
示例#6
0
        public void init(
            bool forSigning,
            CipherParameters param)
        {
            if (forSigning)
            {
                if (typeof(ParametersWithRandom).IsInstanceOfType(param))
                {
                    ParametersWithRandom rParam = (ParametersWithRandom)param;

                    this.random = rParam.getRandom();
                    this.key    = (DSAPrivateKeyParameters)rParam.getParameters();
                }
                else
                {
                    this.random = new SecureRandom();
                    this.key    = (DSAPrivateKeyParameters)param;
                }
            }
            else
            {
                this.key = (DSAPublicKeyParameters)param;
            }
        }
示例#7
0
        /**
         * initialise the cipher.
         *
         * @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 override void init(
            bool forEncryption,
            CipherParameters parameters)
        //throws IllegalArgumentException
        {
            this.forEncryption = forEncryption;

            reset();

            if (typeof(ParametersWithRandom).IsInstanceOfType(parameters))
            {
                ParametersWithRandom p = (ParametersWithRandom)parameters;

                padding.init(p.getRandom());

                cipher.init(forEncryption, p.getParameters());
            }
            else
            {
                padding.init(null);

                cipher.init(forEncryption, parameters);
            }
        }