then the value of the Boundary property is "------------080707010302060306060800".

When building multipart MIME messages, the boundary is automatically generated by methods such as NewMultipartMixed, to be a unique and random string, so explicitly setting the boundary is usually not necessary.

DebugLogFilePath

public string DebugLogFilePath {get; set; }

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes).
A hang or crash should generally never happen. The typical causes of a hang are:

a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,

the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or

there is an internal problem (bug) in the Chilkat code that causes the hang.

LastErrorText

public string LastErrorText {get; }

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

LastMethodSuccess

Indicate whether the last method call succeeded or failed. A value of true indicates success, a value of false indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

Note: The micalg attribute is only present in PKCS7 signed MIME. Setting the Micalg property has the effect of choosing the hash algorithm used w/ signing. Possible choices are "sha1", "md5", "sha256", "sha384", and "sha512". However, it is preferable to set the signing hash algorithm by setting the SigningHashAlg property instead.

NumHeaderFields

NumParts

public int NumParts {get; }

MIME messages are composed of parts in a tree structure. The NumParts property contains the number of direct children. To traverse an entire MIME tree, one would recursively descend the tree structure by iterating from 0 to NumParts-1, calling GetPart to get each direct child MIME object. The traversal would continue by iterating over each child's parts, and so on.

Pkcs7KeyLength

public int Pkcs7KeyLength {get; set; }

When the MIME is encrypted (using PKCS7 public-key encryption), this selects the key length of the underlying symmetric encryption algorithm. The possible values allowed depend on the Pkcs7CryptAlg property. For "aes", the key length may be 128, 192, or 256. For "3des" the key length must be 192. For "des" the key length must be 40. For "rc2" the key length can be 40, 56, 64, or 128.

SigningAlg

Selects the signature algorithm to be used when creating signed (PKCS7) MIME. The default value is "PKCS1-v1_5". This can be set to "RSASSA-PSS" (or simply "pss") to use the RSASSA-PSS signature scheme.

Note: This property only applies when signing with an RSA private key. It does not apply for ECC or DSA private keys.

The default value of this property is true, meaning that "x-" is used by default.
top

VerboseLogging

public bool VerboseLogging {get; set; }

If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

Version

Methods

AddContentLength

public void AddContentLength();

Computes the size of the MIME body and adds a Content-Length header field with the computed value. If the MIME body is non-multipart, the Content-Length is just the size of the content. If the MIME is multipart, then the Content-Length is the sum of all the sub-parts. Calling this method more than once causes the Content-Length header to be re-computed and updated.

AddDecryptCert

Makes a certificate available for decrypting if needed by methods that decrypt, such as UnwrapSecurity. This method may be called multiple times to make more than one certificate (and it's private key) available. Alternative methods for making certificates available are UseCertVault, AddPfxSourceFile, and AddPfxSourceData.

AddDetachedSignature2

Same as AddDetachedSignature, except an extra argument is provided to control whether header fields from the calling MIME object are transferred to the content part of the multipart/signed object. This method transforms the calling object into a multipart/signed MIME with two sub-parts. The first contains the original content of the calling object, and the second contains the digital signature.

AddDetachedSignaturePk

Adds a detached signature using a certificate and it's associated private key. This method would be used when the private key is external to the certificate -- for example, if a PFX/P12 file is not used, but instead a pair of .cer and .pem files are used (one for the certificate and one for the associated private key).

AddDetachedSignaturePk2

Same as AddDetachedSignaturePk, except an extra argument is provided to control whether header fields from the calling MIME object are transferred to the content part of the multipart/signed object. This method transforms the calling object into a multipart/signed MIME with two sub-parts. The first contains the original content of the calling object, and the second contains the digital signature.

AddEncryptCert

Adds a certificate to the object's internal list of certificates to be used when the EncryptN method is called. (See the EncryptN method for more information.) The internal list may be cleared by calling ClearEncryptCerts.

AddPfxSourceData

public bool AddPfxSourceData(byte[] pfxFileData, string pfxPassword);

Adds a PFX to the object's internal list of sources to be searched for certificates and private keys when decrypting . Multiple PFX sources can be added by calling this method once for each. (On the Windows operating system, the registry-based certificate stores are also automatically searched, so it is commonly not required to explicitly add PFX sources.)

The pfxFileData contains the bytes of a PFX file (also known as PKCS12 or .p12).

AddPfxSourceFile

public bool AddPfxSourceFile(string pfxFilePath, string password);

Adds a PFX file to the object's internal list of sources to be searched for certificates and private keys when decrypting. Multiple PFX files can be added by calling this method once for each. (On the Windows operating system, the registry-based certificate stores are also automatically searched, so it is commonly not required to explicitly add PFX sources.)

The pfxFilePath contains the bytes of a PFX file (also known as PKCS12 or .p12).

AppendPart

public bool AppendPart(Mime mime);

Appends a MIME message to the sub-parts of this message. Arbitrarily complex messages with unlimited nesting levels can be created. If the calling Mime object is not already multipart, it is automatically converted to multipart/mixed first.

AsnBodyToXml

public string AsnBodyToXml();

When the body of a MIME part contains PKCS7 (ASN.1 in DER format, base64-encoded), this method can be used to convert the ASN.1 to an XML format for inspection. Here is an example of how an ASN.1 body might look:

ContainsEncryptedParts

Note: This method examines the MIME as-is. If UnwrapSecurity is called and it is successful, then the MIME should no longer contain encrypted parts, and this method would return 0.

Note: If a signed MIME message is then encrypted, then it is not possible to know that the MIME is both encrypted and signed until UnwrapSecurity is called. (In other words, it is not possible to know the contents of the encrypted MIME until it is decrypted.) Therefore, the ContainsSignedParts method would return false.

ContainsSignedParts

Note: This method examines the MIME as-is. If UnwrapSecurity is called and it is successful, then the MIME should no longer contain signed parts, and this method would return 0.

Note: If a signed MIME message is then encrypted, then it is not possible to know that the MIME is both encrypted and signed until UnwrapSecurity is called. (In other words, it is not possible to know the contents of the encrypted MIME until it is decrypted.) Therefore, the ContainsSignedParts method would return false.

Note: The same concept also applies to opaque signatures, such as with the MIME produced by calling ConvertToSigned.

ConvertToMultipartAlt

public bool ConvertToMultipartAlt();

Converts existing MIME to a multipart/alternative. This is accomplished by creating a new outermost multipart/alternative MIME part. The existing MIME is moved into the 1st (and only) sub-part of the new multipart/alternative enclosure. Header fields from the original top-level MIME part are transferred to the new top-level multipart/alternative header, except for Content-Type, Content-Transfer-Encoding, and Content-Disposition. For example, the following simple plain-text MIME is converted as follows:

ConvertToMultipartMixed

public bool ConvertToMultipartMixed();

Converts existing MIME to a multipart/mixed. This is accomplished by creating a new outermost multipart/mixed MIME part. The existing MIME is moved into the 1st (and only) sub-part of the new multipart/mixed enclosure. Header fields from the original top-level MIME part are transferred to the new top-level multipart/mixed header, except for Content-Type, Content-Transfer-Encoding, and Content-Disposition. For example, the following simple plain-text MIME is converted as follows:

ConvertToSigned

Digitally signs a MIME message. The MIME is converted to an application/x-pkcs7-mime which is a PKCS7 signature that includes both the original MIME message and the signature. This is different than AddDetachedSignature, where the signature is appended to the MIME.

ConvertToSignedPk

Digitally signs the MIME to convert it to an "opaque" signed message using a certificate and it's associated private key. This method would be used when the private key is external to the certificate -- for example, if a PFX/P12 file is not used, but instead a pair of .cer and .pem files are used (one for the certificate and one for the associated private key).

Decrypt

public bool Decrypt();

Decrypts PKCS7 encrypted MIME (also known as S/MIME). Information about the certificates required for decryption is always embedded within PKCS7 encrypted MIME. This method will automatically find and use the certificate + private key required from three possible sources:

PFX files that were provided in one or more calls to AddPfxSourceData or AddPfxSourceFile.

Certificates found in an XML certificate vault provided by calling the UseCertVault method.

DecryptUsingCert

DecryptUsingPfxData

public bool DecryptUsingPfxData(byte[] pfxData, string password);

Decrypts MIME using a specific PFX ( also known as PKCS12, which is a file format commonly used to store private keys with accompanying public key certificates, protected with a password-based symmetric key). This method allows the bytes of the PKCS12 file to be passed directly, thus allowing PKCS12's to be persisted and retrieved from non-file-based locations, such as in LDAP or a database.

ExtractPartsToFiles

Recursively descends through the parts of a MIME message and extracts all parts having a filename to a file. The files are created in dirPath. Returns a (Ck)StringArray object containing the names of the files created. The filenames are obtained from the "filename" attribute of the content-disposition header. If a filename does not exist, then the MIME part is not saved to a file.

GetPart

GetSignatureSigningTime

public DateTime GetSignatureSigningTime(int index);

This method is deprecated. It will be removed in a future version.

Returns the signature signing date/time for the Nth signature. The number of signatures (i.e. signer certs) is indicated by the NumSignerCerts property. The HasSignatureSigningTime method may be called to determine if a signature timestamp is available. The index of the 1st signature signing time is 0.

HasSignatureSigningTime

public bool HasSignatureSigningTime(int index);

Returns true if the Nth signature included a timestamp that recorded the signing time. The number of signatures (i.e. signer certs) is indicated by the NumSignerCerts property. (In most cases, the number of signer certs is 1.) The signing time can be obtained via the GetSignatureSigningTime or GetSignatureSigningTimeStr methods. The index of the 1st signature signing time is 0.

IsXml

LastJsonData

Provides information about what transpired in the last method called on this object instance. For many methods, there is no information. However, for some methods, details about what occurred can be obtained by getting the LastJsonData right after the method call returns. For example, after calling UnwrapSecurity, the LastJsonData will return JSON with details about the algorithms used for signature verification and decryption.

SetBodyFromFile

public bool SetBodyFromFile(string fileName);

Sets the MIME message body from the contents of a file. Note: A MIME message consists of a header and a body. The body may itself be a MIME message that consists of a header and body, etc. This method loads the contents of a file into the body of a MIME message, without replacing the header.

The Content-Type and Content-Transfer-Encoding header fields are automatically updated to match the type of content loaded (based on file extension). If your application requires the MIME to have a specific Content-Type and/or Content-Transfer-Encoding, set the ContentType and Encoding properties after calling this method (not before).

SetBodyFromHtml

public bool SetBodyFromHtml(string str);

Sets the MIME message body from a string containing HTML. The Content-Type header is added or updated to the value "text/html".

If 8bit (non-us-ascii) characters are present, and if the Charset property was not previously set, then the "charset" attribute is automatically added to the Content-Type header using the default value of "utf-8". This can be changed at any time by setting the Charset property.

If the Encoding property was not previously set, then the Content-Transfer-Encoding header is automatically added. It will be set to "7bit" or "8bit" depending on whether the HTML body contains 8-bit non-us-ascii characters.

To set the MIME body with no intentional side-effects, use SetBody instead.

SetBodyFromPlainText

public bool SetBodyFromPlainText(string str);

Sets the MIME message body from a string containing plain-text. The Content-Type header is added or updated to the value "text/plain".

If 8bit (non-us-ascii) characters are present, and if the Charset property was not previously set, then the "charset" attribute is automatically added to the Content-Type header using the default value of "utf-8". This can be changed at any time by setting the Charset property.

If the Encoding property was not previously set, then the Content-Transfer-Encoding header is automatically added. It will be set to "7bit" or "8bit" depending on whether the plain-text body contains 8-bit non-us-ascii characters.

To set the MIME body with no intentional side-effects, use SetBody instead.

SetBodyFromXml

public bool SetBodyFromXml(string str);

Sets the MIME message body from a string containing XML. The Content-Type header is added or updated to the value "text/xml".

If 8bit (non-us-ascii) characters are present, and if the Charset property was not previously set, then the "charset" attribute is automatically added to the Content-Type header using the default value of "utf-8". This can be changed at any time by setting the Charset property.

If the Encoding property was not previously set, then the Content-Transfer-Encoding header is automatically added. It will be set to "7bit" or "8bit" depending on whether the plain-text body contains 8-bit non-us-ascii characters.

To set the MIME body with no intentional side-effects, use SetBody instead.

SetCSP

(Only applies to the Microsoft Windows OS) Sets the Cryptographic Service Provider (CSP) to be used for encryption / signing, or decryption / signature verification.

This is not commonly used becaues the default Microsoft CSP is typically appropriate.
One instance where SetCSP is necessary is when using the Crypto-Pro CSP for the GOST R 34.10-2001 and GOST R 34.10-94 providers.

UnwrapSecurity

public bool UnwrapSecurity();

Decrypts and/or verifies all digital signatures contained within the MIME message, and returns true if all decryptions and verifications succeeded. Otherwise returns false. After unwrapping, the information regarding security and certificates can be obtained by the methods GetSignerCert and GetEncryptCert, and the properties NumEncryptCerts and NumSignerCerts.

The MIME is restored to the original structure/content prior to all signing and/or encryption.

The difference between UnwrapSecurity and methods such as Verify or Decrypt is that UnwrapSecurity will recursively traverse the MIME to decrypt and/or verify all parts. Also, UnwrapSecurity will unwrap layers until no further encrypted/signed content is found. For example, if a MIME message was encrypted and then subsequently signed, then UnwrapSecurity will verify and unwrap the detached signature/signed-data layer, and then decrypt the "enveloped data".

UseCertVault

Adds an XML certificate vault to the object's internal list of sources to be searched for certificates and private keys when encrypting/decrypting or signing/verifying. Unlike the AddPfxSourceData and AddPfxSourceFile methods, only a single XML certificate vault can be used. If UseCertVault is called multiple times, only the last certificate vault will be used, as each call to UseCertVault will replace the certificate vault provided in previous calls.

Verify

public bool Verify();

Verifies PKCS7 signed MIME and "unwraps" the signature. The MIME is restored to the original structure that it would have originally had prior to signing. The Verify method works with both detached signatures, as well as opaque/attached signatures.

A PKCS7 signature usually embeds both the signing certificate with its public key. Therefore, it is usually possible to verify a signature without the need to already have the certificate installed. If the signature does not embed the certificate, the Verify method will automatically locate and use the certificate if it was correctly pre-installed on the computer.