The SMIME class implements the S/MIME standard for encryption and decryption with public key cryptography and X.509 digital certificates.
The SMIME class implements the S/MIME V3 standard for encryption and decryption using Public Key Cryptography Standards (PKCS). In addition the class can be used to both generate and verify RSA digital signatures. Using this class for decrypting or signing requires a valid digital certificate with a private key.
Before performing an operation the input and output values should be specified.
Input and Output Properties
The class will determine the source and destination of the input and output based on which properties are set.
The order in which the input properties are checked is as follows:
When a valid source is found the search stops. The order in which the output properties are checked is as follows:
- output_message: The output data is written to this property if no other destination is specified.
The headers of the input message (if any) will be read from input_message_headers or input_message_headers_string.
The headers of the resulting message will be available in the output_message_headers and output_message_headers_string properties.
To sign the current data included in the input message with a certificate, the certificate property must be set to a valid Certificate object for the signing certificate. The include_certificate and detached_signature properties allow you to specify additional details about the signing process. By setting include_certificate to true, digital certificates can be encoded and included in message signature when signing the document. Including a certificate is the preferred method of building signed messages. In addition the SMIME class can also generate PKCS #7 formatted detached digital signatures and envelopes by specifying detached_signature.
To encrypt a message with the class in a PKCS envelope, you must first specify the Certificate for each recipient in the recipient_certs properties to encrypt the message with. You can easily add these with the add_recipient_cert method. Once you have done this you can call the encrypt method to encrypt the message with the recipient certificates.
The result of the encrypted or signed data will be replaced in the output_message property and the output_message_headers property will be filled with the appropriate mime headers if applicable.
Decrypting PKCS envelopes is handled with the decrypt method. When this method is called, the class will attempt to find an appropriate certificate in the certificate property that matches the encrypting certificate. If it cannot find an appropriate certificate an exception will be thrown and the message will not be decrypted.
In addition the SMIME class can be used to verify signatures included in signed messages or documents. After specifying the input, verify_signature can then be used to verify the signature. If the message does not have a certificate attached more then likely an exception will be thrown and the class will not be able to verify the signature. If verify_signature is successful, the signer_cert and signer_cert_chain properties will be filled with the certificate information of the message signer. This information can be used to verify the signing certificates.
The following is the full list of the properties of the class with short descriptions. Click on the links for further details.
|cert_encoded||The certificate (PEM/base64 encoded).|
|cert_store||The name of the certificate store for the client certificate.|
|cert_store_password||If the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store.|
|cert_store_type||The type of certificate store for this certificate.|
|cert_subject||The subject of the certificate used for client authentication.|
|detached_signature||Specifies whether to include a detached signature when signing a message.|
|encrypting_algorithm||Textual description of the encrypting algorithm.|
|include_certificate||Specifies whether to include the signer's certificate with the signed message.|
|include_chain||Specifies whether to include the signer's certificate chain with the signed message.|
|include_headers||Tells the class whether to include the headers when encoding the message.|
|input_file||The file to process.|
|input_message||The message to process.|
|input_message_header_count||The number of records in the InputMessageHeader arrays.|
|input_message_header_field||This property contains the name of the HTTP header (same case as it is delivered).|
|input_message_header_value||This property contains the header contents.|
|input_message_headers_string||String version of headers from the SMIME message.|
|internal_headers||The headers of the MIME entity inside the encrypted or signed message.|
|message_encrypted||Whether or not the current message is encrypted.|
|message_signed||Whether or not the current message is signed.|
|output_file||The output file.|
|output_message||The output message after processing.|
|output_message_header_count||The number of records in the OutputMessageHeader arrays.|
|output_message_header_field||This property contains the name of the HTTP header (same case as it is delivered).|
|output_message_header_value||This property contains the header contents.|
|output_message_headers_string||String version of headers from the SMIME message.|
|overwrite||Indicates whether or not the class should overwrite files.|
|recipient_cert_count||The number of records in the RecipientCert arrays.|
|recipient_cert_encoded||The certificate (PEM/base64 encoded).|
|recipient_cert_store||The name of the certificate store for the client certificate.|
|recipient_cert_store_password||If the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store.|
|recipient_cert_store_type||The type of certificate store for this certificate.|
|recipient_cert_subject||The subject of the certificate used for client authentication.|
|signer_cert_encoded||The certificate (PEM/base64 encoded).|
|signer_cert_issuer||The issuer of the certificate.|
|signer_cert_serial_number||The serial number of the certificate encoded as a string.|
|signer_cert_store||The name of the certificate store for the client certificate.|
|signer_cert_store_password||If the certificate store is of a type that requires a password, this property is used to specify that password in order to open the certificate store.|
|signer_cert_store_type||The type of certificate store for this certificate.|
|signer_cert_subject||The subject of the certificate used for client authentication.|
|signer_cert_chain_count||The number of records in the SignerCertChain arrays.|
|signer_cert_chain_encoded||The certificate (PEM/base64 encoded).|
|signing_algorithm||Textual description of the signature hash algorithm.|
|use_oaep||Whether to use Optimal Asymmetric Encryption Padding (OAEP).|
|use_pss||Whether to use RSA-PSS during signing and verification.|
The following is the full list of the methods of the class with short descriptions. Click on the links for further details.
|add_recipient_cert||Used to add recipient certificates used to encrypt messages.|
|config||Sets or retrieves a configuration setting.|
|decrypt||Decrypts the current Message .|
|decrypt_and_verify_signature||Decrypts and verifies the signature of the current message.|
|encrypt||Encrypts the message.|
|get_recipient_info||Gets the recipient infos for an encrypted message.|
|get_signer_cert_info||Gets the signature information for an signed message.|
|reset||Resets the class properties.|
|sign||Signs the current message.|
|sign_and_encrypt||Signs and encrypts the current message.|
|verify_signature||Verifies the signature of the current message.|
The following is the full list of the events fired by the class with short descriptions. Click on the links for further details.
|on_error||Information about errors during data delivery.|
|on_recipient_info||Fired for each recipient certificate of the encrypted message.|
|on_signer_cert_info||Fired during verification of the signed message.|
The following is a list of configuration settings for the class with short descriptions. Click on the links for further details.
|ApplyB64Encoding||Instructs the class to base64 encode the message when signing or encrypting.|
|CSP||The Cryptographic Service Provider.|
|GenerateSignatureTimestamp||Whether to generate timestamps in signatures.|
|IncludeHeaders||Tells the class whether to include the headers when encoding the message.|
|IncludeInternalHeaders||Tells the class whether or not to include the internal headers when encoding the message.|
|InputContentTransferEncoding||Sets the Content-Transfer-Encoding for the signed message.|
|InputContentType||Sets the Content-Type for the signed message.|
|InputMessageEncrypted||Whether or not the input message is encrypted.|
|InputMessageSigned||Whether or not the input message is signed.|
|OAEPMGF1HashAlgorithm||The MGF1 hash algorithm used with OAEP.|
|OAEPParams||The hex encoded OAEP parameters.|
|OAEPRSAHashAlgorithm||The RSA hash algorithm used with OAEP.|
|ParseInternalHeaders||Tells the class whether or not to parse the message part headers when decrypting a message.|
|RecipientCert||Used to specify the public certificate when using a PEM key to decrypt.|
|RecipientCertFile||Used to specify the public certificate file when using a PEM key to decrypt.|
|RecipientInfoType||The type of signer information to include in the signed message.|
|SignerInfoType||The type of signer information to include in the signed message.|
|UseAlgorithmOIDs||Whether OIDs are used when providing information about the algorithms.|
|UseCryptoAPI||Whether to use the Microsoft Crypto API for cryptographic message generation.|
|BuildInfo||Information about the product's build.|
|CodePage||The system code page used for Unicode to Multibyte translations.|
|LicenseInfo||Information about the current license.|
|ProcessIdleEvents||Whether the class uses its internal event loop to process events when the main thread is idle.|
|SelectWaitMillis||The length of time in milliseconds the class will wait when DoEvents is called if there are no events to process.|
|UseInternalSecurityAPI||Tells the class whether or not to use the system security libraries or an internal implementation.|