コード例 #1
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,
            ICipherParameters	parameters)
        {
            if (parameters is ParametersWithRandom)
            {
                ParametersWithRandom p = (ParametersWithRandom) parameters;

                this.key = (ElGamalKeyParameters) p.Parameters;
                this.random = p.Random;
            }
            else
            {
                this.key = (ElGamalKeyParameters) parameters;
                this.random = new SecureRandom();
            }

            this.forEncryption = forEncryption;
            this.bitSize = key.Parameters.P.BitLength;

            if (forEncryption)
            {
                if (!(key is ElGamalPublicKeyParameters))
                {
                    throw new ArgumentException("ElGamalPublicKeyParameters are required for encryption.");
                }
            }
            else
            {
                if (!(key is ElGamalPrivateKeyParameters))
                {
                    throw new ArgumentException("ElGamalPrivateKeyParameters are required for decryption.");
                }
            }
        }
コード例 #2
0
 protected bool Equals(
     ElGamalKeyParameters other)
 {
     return Platform.Equals(parameters, other.parameters)
         && base.Equals(other);
 }