VerifySignature Method

This method verifys the validity of current email's digital signature

[Syntax]
C++: HRESULT VerifySignature( long VerifyFlag, long AutoDecode, IDispatch* *pVal )
Visual Basic: VerifySignature( VerifyFlag As Long, AutoDecode As Long ) As Object
C#: Object VerifySignature(int verifyFlag, int AutoDecode )

Parameters

VerifyFlag

If this parameter is zero, then only the signature is checked, otherwise both the validity of the certificate and the validity of the signature are checked

AutoDecode

If this parameter is greater than zero(recommended), the content attached in signature is decode automatically.

Return Value

If this method verifys signature successfully, return value is a CAPICOM.SignedData object associated with current signed email, otherwise an exception is thrown out.

Remarks

If current email is signed and encrypted, decryption should be the first step.

ANPOP uses CAPICOM object(a free component of Microsoft) to verify signature and decrypt email, CAPICOM is included in ANPOP installation package. More detail about CAPICOM, please click here.

Usage Example

[Visual Basic]

'Note: current project should add the reference for ANSMTP and CAPICOM
Sub DecryptAndVerifyMessage( ByRef oMsg As ANPOPLib.POPMSG )
  Dim oSignedData As CAPICOM.SignedData
  On Error GoTo ErrorHandler
  If oMsg.IsEncrypted() > 0 Then
    Set oMsg = oMsg.Decrypt() 'decrypt message
  End If
  
  If oMsg.IsSigned() > 0 Then
    Set SignedData = oMsg.VerifySignature(0,1)
    SignedData.Signers(1).Certificate.Display 'display certificate
    'adding this certificate to LOCAL_CURRENT_USER "my" store is recommended
  End If
  
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & ": " & Err.Description, , "Error:"  
End Sub
[C#]
'Note: current project should add the reference for ANSMTP and CAPICOM
using System;
using ANPOPLib;
using CAPICOM;

void DecryptAndVerifyMessage( ref POPMSGClass oMsg )
{
  try
  {
    if( oMsg.IsEncrypted() > 0 )
      oMsg.RawContent = oMsg.Decrypt().RawContent;  //decrypt message
      
    CAPICOM.ISignedData oSignedData = null; 
    if( oMsg.IsSigned() > 0 )
    {
      oSignedData = (CAPICOM.ISignedData)oMsg.VerifySignature(0, 1);
      //display certificate
      CAPICOM.ISigner oSigner = (CAPICOM.ISigner)oSignedData.Signers[1];
      oSigner.Certificate.Display();
      //adding this certificate to LOCAL_CURRENT_USER "my" store is recommended    
    }
  }
  catch( Exception e )
  {
    Console.WriteLine( e.Message );
  }
}
[Visual C++]
#include "stdafx.h"
#include <comdef.h>
#include <iostream>

#import "C:\Program Files\AdminSystem.NET\ANPOP\CAPICOM.dll" \
                                  no_namespace
#import "C:\Program Files\AdminSystem.NET\ANPOP\ANPOP.dll" \
                                  rename_namespace("ANPOPLib")

using namespace ANPOPLib;
using namespace std;
	
void DecryptAndVerifyMessage( IPOPMSGPtr& oMsg )
{
  try
  {
    if( oMsg->IsEncrypted() > 0 )
      oMsg = oMsg->Decrypt(); //decrypt message
      
    ISignedDataPtr oSignedData = NULL;
    if( oMsg->IsSigned() > 0 )
    {
      oSignedData = oMsg->VerifySignature(0, 1);
      //display certificate
      ISignerPtr oSigner = oSignedData->Signers->Item[1];
      oSigner->Certificate->Display();
      //adding this certificate to LOCAL_CURRENT_USER "my" store is recommended      
    }
   }
   catch( _com_error &e )
   {
     cout << (const char*)e.Description() << endl;
   }
}

See Also

IsSigned Method
IsEncrypted Method
Decrypt Method


2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.