CryptoMessage Object

Overview

The CryptoMessage object provides PKCS#7-based message signature and encryption functionality. This object is used by the AspEmail component to send secure mail in the S/MIME format. Starting with Version 2.0, it can also be used to generate detached PKCS#7 signatures and envelopes.

Member List

Properties

This object has no properties.

Methods


Sub AddRecipientCert(Cert As CryptoCert)

Adds a recipient certificate to the message when this CryptoMessage object is to be used for sending encrypted mail or generating PKCS#7 envelopes. This method can be called as many times as there are message recipients.

Usage:

Msg.AddRecipientCert Cert

Related Section: 5.2 CryptoMessage Object.


Function DecryptText(Envelope As String, Context As String) As String

Decrypts a specified PKCS#7 envelope using the specified private key context name. The latter can be obtained via Cert.PrivateKeyContext.ContainerName. If Context is an empty string, all certificate contexts in the MY store will be tried until a match is found. If there is no match, an error will be thrown.

Returns value: a decrypted string of text.

Usage:

EncrText = Msg.DecryptText(EncrText, "")

Related Section: 9.2 Encrypting & Decrypting Text Directly with Certificates.


Function EncryptText(Text As String) As String

Encrypts a specified text string with one or more certificates specified by AddRecipientCert.

Returns value: a Base64-encoded PKCS#7 envelope (encrypted message).

Usage:

EncrText = Msg.EncryptText("secret")

Related Section: 9.2 Encrypting & Decrypting Text Directly with Certificates.


Sub SetSignerCert(Cert As CryptoCert)

Sets the signer certificate for the message when this CryptoMessage object is to be used for sending signed mail or generating detached PKCS#7 signatures

Usage:

Msg.SetSignerCert Cert

Related Section: 5.4 Signed Email


Function SignFile(Path As String) As String

Computes the detached PKCS#7 signature of the specified file using a certificate specified by SetSignerCert. Signatures are based on the SHA hash function.

Returns value: a Base64-encoded PKCS#7 signature blob.

Usage:

Signature = Msg.SignFile("c:\path\myfile.ext")

Related Section: 9.4 Generating and Verifying Detached PKCS#7 Signatures.


Function SignHash(Value As CryptoBlob) As CryptoBlob

Computes the detached PKCS#7 signature of the specified SHA1 value using a certificate specified by SetSignerCert. Currently, only 20-byte values are supported as the input. Introduced in Version 2.9 to implement the client-side signing of server-side data.

Returns value: a CryptoBlob object populated with the PKCS#7 signature data.

Usage:

Set SigBlob = Msg.SignHash(HashBlob)

Related Section: 9.4.3 Client-Side Signing of Server-Side Data.


Function SignText(Text As String) As String

Computes the detached PKCS#7 signature of the specified text string using a certificate specified by SetSignerCert. Signatures are based on the SHA hash function.

Returns value: a Base64-encoded PKCS#7 signature blob.

Usage:

Signature = Msg.SignText("some text")

Related Section: 9.4 Generating and Verifying Detached PKCS#7 Signatures.


Function VerifySignature(Signature As String, Hash As CryptoHash, Cert As CryptoCert) As Boolean

Verifies a detached PKCS#7 signature specified by Signature against a hash value contained in Hash and a public key contained in Cert.

Returns value: True if the signature is verified, or False otherwise.

Usage:

Set Cert = CM.ImportCertFromFile("c:\mycert.cer")
Set Hash = Context.CreateHash ' SHA by default
Hash.AddText "secret"
SignatureValid = Msg.VerifySignature(Signature, Hash, Cert)

Related Section: 9.4 Generating and Verifying Detached PKCS#7 Signatures.

CryptoHash CryptoCert