Ejemplo n.º 1
0
        /**
         * Add multiple key agreement based recipients (sharing a single KeyAgreeRecipientInfo structure).
         *
         * @param agreementAlgorithm key agreement algorithm to use.
         * @param senderPrivateKey private key to initialise sender side of agreement with.
         * @param senderPublicKey sender public key to include with message.
         * @param recipientCerts recipients' public key certificates.
         * @param cekWrapAlgorithm OID for key wrapping algorithm to use.
         * @exception SecurityUtilityException if the algorithm requested cannot be found
         * @exception InvalidKeyException if the keys are inappropriate for the algorithm specified
         */
        public void AddKeyAgreementRecipients(
            string agreementAlgorithm,
            AsymmetricKeyParameter senderPrivateKey,
            AsymmetricKeyParameter senderPublicKey,
            ICollection recipientCerts,
            string cekWrapAlgorithm)
        {
            if (!senderPrivateKey.IsPrivate)
            {
                throw new ArgumentException("Expected private key", "senderPrivateKey");
            }
            if (senderPublicKey.IsPrivate)
            {
                throw new ArgumentException("Expected public key", "senderPublicKey");
            }

            /* TODO
             * "a recipient X.509 version 3 certificate that contains a key usage extension MUST
             * assert the keyAgreement bit."
             */

            KeyAgreeRecipientInfoGenerator karig = new KeyAgreeRecipientInfoGenerator();

            karig.KeyAgreementOID  = new DerObjectIdentifier(agreementAlgorithm);
            karig.KeyEncryptionOID = new DerObjectIdentifier(cekWrapAlgorithm);
            karig.RecipientCerts   = recipientCerts;
            karig.SenderKeyPair    = new AsymmetricCipherKeyPair(senderPublicKey, senderPrivateKey);

            recipientInfoGenerators.Add(karig);
        }
		/**
		 * Add multiple key agreement based recipients (sharing a single KeyAgreeRecipientInfo structure).
		 *
		 * @param agreementAlgorithm key agreement algorithm to use.
		 * @param senderPrivateKey private key to initialise sender side of agreement with.
		 * @param senderPublicKey sender public key to include with message.
		 * @param recipientCerts recipients' public key certificates.
		 * @param cekWrapAlgorithm OID for key wrapping algorithm to use.
		 * @exception SecurityUtilityException if the algorithm requested cannot be found
		 * @exception InvalidKeyException if the keys are inappropriate for the algorithm specified
		 */
		public void AddKeyAgreementRecipients(
			string					agreementAlgorithm,
			AsymmetricKeyParameter	senderPrivateKey,
			AsymmetricKeyParameter	senderPublicKey,
			ICollection				recipientCerts,
			string					cekWrapAlgorithm)
		{
			if (!senderPrivateKey.IsPrivate)
				throw new ArgumentException("Expected private key", "senderPrivateKey");
			if (senderPublicKey.IsPrivate)
				throw new ArgumentException("Expected public key", "senderPublicKey");

			/* TODO
			 * "a recipient X.509 version 3 certificate that contains a key usage extension MUST
			 * assert the keyAgreement bit."
			 */

			KeyAgreeRecipientInfoGenerator karig = new KeyAgreeRecipientInfoGenerator();
			karig.KeyAgreementOID = new DerObjectIdentifier(agreementAlgorithm);
			karig.KeyEncryptionOID = new DerObjectIdentifier(cekWrapAlgorithm);
			karig.RecipientCerts = recipientCerts;
			karig.SenderKeyPair = new AsymmetricCipherKeyPair(senderPublicKey, senderPrivateKey);

			recipientInfoGenerators.Add(karig);
		}