Esempio n. 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.");
				}
			}
		}
Esempio n. 2
0
        public override bool Equals(
            object obj)
        {
            if (obj == this)
            {
                return(true);
            }

            ElGamalKeyParameters other = obj as ElGamalKeyParameters;

            if (other == null)
            {
                return(false);
            }

            return(Equals(other));
        }
		protected bool Equals(
			ElGamalKeyParameters other)
		{
			return Platform.Equals(parameters, other.parameters)
				&& base.Equals(other);
		}
Esempio n. 4
0
 protected bool Equals(
     ElGamalKeyParameters other)
 {
     return(Platform.Equals(parameters, other.parameters) &&
            base.Equals(other));
 }