SmimeDecrypt2 Method
Decrypts an e-mail message if it's encrypted.

Namespace: MailBee.Security
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public SmimeResult Decrypt2(
	MailMessage message,
	X509Certificate2Collection extraCerts
)

Parameters

message
Type: MailBee.MimeMailMessage
The original encrypted message to be decrypted.
extraCerts
Type: System.Security.Cryptography.X509CertificatesX509Certificate2Collection
The certificates to be searched for the appropriate certificate for decrypting the message (in addition to the Personal storage), or a null reference (Nothing in Visual Basic) if only Personal system storage should be used.

Return Value

Type: SmimeResult
A reference to SmimeResult object containing either the decrypted message or the original message if it was not encrypted; a null reference (Nothing in Visual Basic) if the decryption process failed.
Exceptions
ExceptionCondition
MailBeeInvalidArgumentExceptionmessage is a null reference (Nothing in Visual Basic).
MailBeeCertificateExceptionA cryptographic error occurred and ThrowExceptions is true. Typically, if the error message is "Keyset does not exist", indicates that there is no private key in the certicate required for decryption.
Remarks

This method looks for the appropriate certificate for decryption in the Personal storage and in the specified certificates. The certificate in question must contain a private key.

To access the decrypted message, use DecryptedMessage property of the returned SmimeResult object. To get the certificate used for decryption, use DecryptionCertificate property of the same object.

To check if the original message was encrypted, examine IsEncrypted property value of the original MailMessage object.

To decrypt and verify a message within a single method call, use DecryptAndVerify(MailMessage, MessageVerificationFlags) method or its overloads.

This method is a version of Decrypt(MailMessage, CertificateStore) which accepts X509Certificate2Collection rather than CertificateStore. Starting from .NET Standard 2.0, you must use this method as CertificateStore functionality has been reduced to avoid dependency on Win32 API.

See Also