Beispiel #1
0
            public override void AddSessionInfo(
                byte[]                  si,
                SecureRandom random)
            {
                IBufferedCipher c;

                switch (pubKey.Algorithm)
                {
                case PublicKeyAlgorithmTag.RsaEncrypt:
                case PublicKeyAlgorithmTag.RsaGeneral:
                    c = CipherUtilities.GetCipher("RSA//PKCS1Padding");
                    break;

                case PublicKeyAlgorithmTag.ElGamalEncrypt:
                case PublicKeyAlgorithmTag.ElGamalGeneral:
                    c = CipherUtilities.GetCipher("ElGamal/ECB/PKCS1Padding");
                    break;

                case PublicKeyAlgorithmTag.Dsa:
                    throw new PgpException("Can't use DSA for encryption.");

                case PublicKeyAlgorithmTag.ECDsa:
                    throw new PgpException("Can't use ECDSA for encryption.");

                default:
                    throw new PgpException("unknown asymmetric algorithm: " + pubKey.Algorithm);
                }

                AsymmetricKeyParameter akp = pubKey.GetKey();

                c.Init(true, new ParametersWithRandom(akp, random));

                byte[] encKey = c.DoFinal(si);

                switch (pubKey.Algorithm)
                {
                case PublicKeyAlgorithmTag.RsaEncrypt:
                case PublicKeyAlgorithmTag.RsaGeneral:
                    data = new BigInteger[] { new BigInteger(1, encKey) };
                    break;

                case PublicKeyAlgorithmTag.ElGamalEncrypt:
                case PublicKeyAlgorithmTag.ElGamalGeneral:
                    int halfLength = encKey.Length / 2;
                    data = new BigInteger[]
                    {
                        new BigInteger(1, encKey, 0, halfLength),
                        new BigInteger(1, encKey, halfLength, halfLength)
                    };
                    break;

                default:
                    throw new PgpException("unknown asymmetric algorithm: " + encAlgorithm);
                }
            }
Beispiel #2
0
 public void InitVerify(
     PgpPublicKey pubKey)
 {
     lastb = 0;
     if (sig == null)
     {
         GetSig();
     }
     try
     {
         sig.Init(false, pubKey.GetKey());
     }
     catch (InvalidKeyException e)
     {
         throw new PgpException("invalid key.", e);
     }
 }
		/// <summary>Initialise the signature object for verification.</summary>
        public void InitVerify(
            PgpPublicKey pubKey)
        {
			lastb = 0;

			try
			{
				sig = SignerUtilities.GetSigner(
					PgpUtilities.GetSignatureName(sigPack.KeyAlgorithm, sigPack.HashAlgorithm));
			}
			catch (Exception e)
			{
				throw new PgpException("can't set up signature object.",  e);
			}

			try
            {
                sig.Init(false, pubKey.GetKey());
            }
			catch (InvalidKeyException e)
            {
                throw new PgpException("invalid key.", e);
            }
        }
Beispiel #4
0
        /// <summary>Initialise the signature object for verification.</summary>
        public void InitVerify(
            PgpPublicKey pubKey)
        {
            lastb = 0;

            try
            {
                sig = SignerUtilities.GetSigner(
                    PgpUtilities.GetSignatureName(sigPack.KeyAlgorithm, sigPack.HashAlgorithm));
            }
            catch (Exception e)
            {
                throw new PgpException("can't set up signature object.", e);
            }

            try
            {
                sig.Init(false, pubKey.GetKey());
            }
            catch (InvalidKeyException e)
            {
                throw new PgpException("invalid key.", e);
            }
        }
		public void InitVerify(
            PgpPublicKey pubKey)
        {
			lastb = 0;
            if (sig == null)
            {
                GetSig();
            }
            try
            {
                sig.Init(false, pubKey.GetKey());
            }
            catch (InvalidKeyException e)
            {
                throw new PgpException("invalid key.", e);
            }
        }