IsEncrypted Method

This method checks if current email is encrypted by encryption certification

[Syntax]
C++: HRESULT IsEncrypted( long* pVal )
Visual Basic: IsEncrypted() As long
C#: int IsEncrypted()

Return Value

Return value is greater than zero if current email is encrypted, otherwise return value is non-zero.

Remarks

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

VerifySignature Method
IsSigned Method
Decrypt Method


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