Ejemplo 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.");
                }
            }
        }
Ejemplo n.º 2
0
 public virtual void Init(bool forEncryption, ICipherParameters parameters)
 {
     //IL_007c: Unknown result type (might be due to invalid IL or missing references)
     //IL_0094: Unknown result type (might be due to invalid IL or missing references)
     if (parameters is ParametersWithRandom)
     {
         ParametersWithRandom parametersWithRandom = (ParametersWithRandom)parameters;
         key    = (ElGamalKeyParameters)parametersWithRandom.Parameters;
         random = parametersWithRandom.Random;
     }
     else
     {
         key    = (ElGamalKeyParameters)parameters;
         random = new SecureRandom();
     }
     this.forEncryption = forEncryption;
     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.");
     }
 }
 protected bool Equals(ElGamalKeyParameters other)
 {
     if (object.Equals(parameters, other.parameters))
     {
         return(Equals((AsymmetricKeyParameter)other));
     }
     return(false);
 }
    public override bool Equals(object obj)
    {
        if (obj == this)
        {
            return(true);
        }
        ElGamalKeyParameters elGamalKeyParameters = obj as ElGamalKeyParameters;

        if (elGamalKeyParameters == null)
        {
            return(false);
        }
        return(Equals(elGamalKeyParameters));
    }
Ejemplo n.º 5
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;
        }