GDSecureMimeDecoder Class |
Namespace: GD
public sealed class GDSecureMimeDecoder
The GDSecureMimeDecoder type exposes the following members.
Name | Description | |
---|---|---|
GDSecureMimeDecoder | Construct a new decoder with an IBuffer provided as primary input. |
Name | Description | |
---|---|---|
Buffer | Gets or sets the current data buffer. | |
ClearTextContent | Gets the clear text content of the decoded message, if any. | |
DecryptionCertificates | Gets certificates used in the last decryption. Sets certificates for the next one. | |
IsEncrypted | Gets encrypted status of the message. | |
IsSigned | Gets signed status of the message. | |
SignerCertificates | Gets certificates used to verify signed message. |
Name | Description | |
---|---|---|
DecodeAsync | Decodes an SMIME message. | |
DecryptAsync | Decrypts an SMIME message. | |
Equals | (Inherited from Object.) | |
GetHashCode | (Inherited from Object.) | |
GetType | (Inherited from Object.) | |
ProcessMessageAsync | A helper function which will decrypt, verify and extract clear text content from an SMIME message. | |
ToString | (Inherited from Object.) | |
VerifySignatureAsync | Verify signature of a signed SMIME message using default options. | |
VerifySignatureAsync(GDSMIMESignatureVerificationOptions) | Verify signature of a signed SMIME message. | |
VerifySignatureAsync(GDSMIMESignatureVerificationOptions, String) | Verify signature of a signed SMIME message. |
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)); }