Example #1
0
		/// <summary>
		/// Initialize a new instance of the <see cref="CmsRecipient"/> class.
		/// </summary>
		/// <remarks>
		/// <para>Creates a new <see cref="CmsRecipient"/> based on the provided certificate.</para>
		/// <para>If the X.509 certificate contains an S/MIME capability extension, the initial value of the
		/// <see cref="EncryptionAlgorithms"/> property will be set to whatever encryption algorithms are
		/// defined by the S/MIME capability extension, otherwise int will be initialized to a list
		/// containing only the Triple-Des encryption algorithm which should be safe to assume for all
		/// modern S/MIME v3.x client implementations.</para>
		/// </remarks>
		/// <param name="certificate">The recipient's certificate.</param>
		/// <param name="recipientIdentifierType">The recipient identifier type.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="certificate"/> is <c>null</c>.
		/// </exception>
		public CmsRecipient (X509Certificate2 certificate, SubjectIdentifierType recipientIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber)
		{
			if (certificate == null)
				throw new ArgumentNullException (nameof (certificate));

			if (recipientIdentifierType != SubjectIdentifierType.SubjectKeyIdentifier)
				RecipientIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
			else
				RecipientIdentifierType = SubjectIdentifierType.SubjectKeyIdentifier;

			EncryptionAlgorithms = certificate.GetEncryptionAlgorithms ();
			Certificate = certificate.AsBouncyCastleCertificate ();
		}