SignAndEncrypt Method


Signs the message using the private key contained in the sender's certificate and encrypts this message using the public key contained in the recipient's certificate.

The digital signature allows recipients to confirm the authenticity of the message sender and verify message integrity.


[Visual Basic]

blnResult = ObjectName.SignAndEncrypt

 
Parameters: None 
Return value As Boolean True if successful, False if error has occurred.  
Remarks:

Before using this method, the sender's and the recipient's certificates should be selected using SelectSenderCert and AddRecipientCert methods.


Usage example:

' This example loads the message from file, signs and encrypts this message.

Dim objSMIME, objMsg

' Using Visual Basic to create the objects
Set objMsg = CreateObject("MailBee.Message")
Set objSMIME = CreateObject("MailBee.SMIME")

' Using ASP to create the objects
'Set objMsg = Server.CreateObject("MailBee.Message")
'Set objSMIME = Server.CreateObject("MailBee.SMIME")

' Specify MailBee license key
objSMIME.LicenseKey = "put your license key here"

' Load the message from file
objMsg.ImportFromFile "mail_src.eml"

' Specify the message for the further processing
Set objSMIME.Message = objMsg

' These lines are needed if we want to use SHA-256 signature (required by Thunderbird)
objSMIME.CSP = "Microsoft Strong Cryptographic Provider"
objSMIME.AlgorithmSigning = "2.16.840.1.101.3.4.2.1"

' Select the sender's certificate form the system storage and the recipient's certificate from address book 
If (objSMIME.SelectSenderCert ("MY", 0, "","", "", objMsg.PureFromAddr, "")) And _
	(objSMIME.AddRecipientCert ("AddressBook", 0, "", "", "", objMsg.PureToAddr)) Then
	' Sign and encrypt the message
	objSMIME.SignAndEncrypt

	' Check if any errors occurred
	If (objSMIME.SMIMEError <> 0) Or (objSMIME.SMIMESpecificError <> 0) Then
		' Display the code of the occurred error
		' In ASP use Response.Write instead of MsgBox
	    MsgBox "SMIMEError = " & objSMIME.SMIMEError & "   SMIMESpecificError = " & _
	      objSMIME.SMIMESpecificError
	End If
End If


See Also:

SelectSenderCert Method, AddRecipientCert Method, Sign Method, Encrypt Method


Copyright © 2002-2024, AfterLogic Corporation. All rights reserved.