Click or drag to resize
GDSecureMimeDecoder Class
Decoder class used to decode, decrypt and verify signature of an SMIME message.
Inheritance Hierarchy
SystemObject
  GDGDSecureMimeDecoder

Namespace:  GD
Assembly:  GD (in GD.dll) Version: 255.255.255.255
Syntax
public sealed class GDSecureMimeDecoder

The GDSecureMimeDecoder type exposes the following members.

Constructors
  NameDescription
Public methodGDSecureMimeDecoder
Construct a new decoder with an IBuffer provided as primary input.
Top
Properties
  NameDescription
Public propertyBuffer
Gets or sets the current data buffer.
Public propertyClearTextContent
Gets the clear text content of the decoded message, if any.
Public propertyDecryptionCertificates
Gets certificates used in the last decryption. Sets certificates for the next one.
Public propertyIsEncrypted
Gets encrypted status of the message.
Public propertyIsSigned
Gets signed status of the message.
Public propertySignerCertificates
Gets certificates used to verify signed message.
Top
Methods
  NameDescription
Public methodDecodeAsync
Decodes an SMIME message.
Public methodDecryptAsync
Decrypts an SMIME message.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodProcessMessageAsync
A helper function which will decrypt, verify and extract clear text content from an SMIME message.
Public methodToString (Inherited from Object.)
Public methodVerifySignatureAsync
Verify signature of a signed SMIME message using default options.
Public methodVerifySignatureAsync(GDSMIMESignatureVerificationOptions)
Verify signature of a signed SMIME message.
Public methodVerifySignatureAsync(GDSMIMESignatureVerificationOptions, String)
Verify signature of a signed SMIME message.
Top
Examples

Following example shows how to implement a simple message decoding loop. For brievety exception handling was omitted.

//IBuffer encryptedMessage contains the message received, that we want to decode/decrypt/verify
GDSecureMimeDecoder decoder = new GDSecureMimeDecoder(encryptedMessage);
GDSecureMimeError decoderResult = await decoder.DecodeAsync();

if (decoderResult != GDSecureMimeError.None)
{
    return;
}

if (decoder.ClearTextContent != null && decoder.ClearTextContent.Length > 0)
{
    Debug.WriteLine("Clear text content present: " + CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, decoder.ClearTextContent));
}

//a simple loop for decrypting/verifying multipart message
do
{
    if (decoder.IsEncrypted)
    {
        var decryptResult = await decoder.DecryptAsync();
        if (decryptResult != GDSecureMimeError.None)
        {
            Debug.WriteLine("Failed to decrypt encrypted message with error: " + decryptResult);
            break;
        }
    }
    else if (decoder.IsSigned)
    {
        var verifyResult = await decoder.VerifySignatureAsync();
        if (verifyResult != GDSecureMimeError.None)
        {
            Debug.WriteLine("Failed to verify signature with error: " + verifyResult);
            break;
        }
    }
}
while (await decoder.DecodeAsync() == GDSecureMimeError.None);

Debug.WriteLine("Final message: " + CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, decoder.Buffer));

Alternatively one can use ProcessMessageAsync(GDSMIMESignatureVerificationOptions, String) which implements such loop.

//IBuffer encryptedMessage contains the message received, that we want to decode/decrypt/verify
GDSecureMimeDecoder decoder = new GDSecureMimeDecoder(encryptedMessage);

GDSMIMEProcessMessageOutput output = await decoder.ProcessMessageAsync(GDSMIMESignatureVerificationOptions.StrictSignatureCheck, string.Empty);

if (output.Error != GDSMIMEProcessMessageError.Success)
{
    Debug.WriteLine("Failed to decode message with error:" + output.Error);
}
else
{
    Debug.WriteLine("Clear text:" + CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, output.ClearTextContent))
    Debug.WriteLine("Final message: " + CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, output.FinalMessage));
}
See Also

Reference