Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(DataFlex) Send a Signed Email using RSASSA-PSS with SHA256

Demonstrates how to sign and send an email using the RSASSA-PSS signing algorithm with the SHA256 hash algorithm.

Note: This example requires Chilkat v9.5.0.67 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoPfx
    Boolean iSuccess
    Variant vEmail
    Handle hoEmail
    Variant vCert
    Handle hoCert
    Handle hoMailman
    String sTemp1
    Boolean bTemp1

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Get a digital certificate with private key from a .pfx
    // (Chilkat has many different ways to provide a cert + private key for siging.
    // Using a PFX is just one possible option.)
    Get Create (RefClass(cComChilkatPfx)) To hoPfx
    If (Not(IsComObjectCreated(hoPfx))) Begin
        Send CreateComObject of hoPfx
    End
    Get ComLoadPfxFile Of hoPfx "qa_data/rsassa-pss/privatekey.pfx" "PFX_PASSWORD" To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoPfx To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    // Create a simple email.
    Set ComSubject Of hoEmail To "Sample RSASSA-PSS Signed Email"
    Set ComBody Of hoEmail To "Sample RSASSA-PSS Signed Email"
    Set ComFrom Of hoEmail To "from_name@mydomain.com"
    // Add one ore more recipients..
    Get ComAddTo Of hoEmail "Chilkat Support" "support@chilkatsoft.com" To iSuccess
    Get ComAddTo Of hoEmail "Chilkat GMail" "chilkat.support@gmail.com" To iSuccess

    // Indicate that the email is to be signed, and that we want to use RSASSA-PSS.
    Set ComSendSigned Of hoEmail To True
    Set ComSigningAlg Of hoEmail To "pss"
    Set ComSigningHashAlg Of hoEmail To "sha256"

    // Get the certificate to be used for signing.
    // (The typical case for a PFX is that it contains a cert with an associated private key,
    // as well as other certificates in the chain of authentication.  The cert with the private
    // key should be in the first position at index 0.)
    Get ComGetCert Of hoPfx 0 To vCert
    If (IsComObject(vCert)) Begin
        Get Create (RefClass(cComChilkatCert)) To hoCert
        Set pvComObject Of hoCert To vCert
    End
    Get ComLastMethodSuccess Of hoPfx To bTemp1
    If (bTemp1 <> True) Begin
        Get ComLastErrorText Of hoPfx To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Tell the email object to use this cert (and private key) for signing.
    Get ComSetSigningCert Of hoEmail vCert To iSuccess
    Send Destroy of hoCert

    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    // Set the SMTP settings for your email account on your mail server.
    Set ComSmtpUsername Of hoMailman To "SMTP_LOGIN"
    Set ComSmtpPassword Of hoMailman To "SMTP_PASSWORD"
    Set ComSmtpHost Of hoMailman To "MY_SMTP_DOMAIN_OR_IP"
    Set ComSmtpPort Of hoMailman To 587
    Set ComStartTLS Of hoMailman To True

    // Signed email can be sent in two different ways.  
    // In a multipart/signed email, the signature is attached as a separate MIME part.
    // In an opaque email (signedData) the content of the email is encapsulated within the signature
    // and the email is sent as "application/pkcs7-mime". 
    // Either should be fine, but some receiving systems might require one or the other..
    Set ComOpaqueSigning Of hoMailman To False

    // Send the email.  The mailman will sign the email as directed by the 
    // property settings of the email object.
    Get pvComObject of hoEmail to vEmail
    Get ComSendEmail Of hoMailman vEmail To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComCloseSmtpConnection Of hoMailman To iSuccess
    If (iSuccess <> True) Begin
        Showln "Connection to SMTP server not closed cleanly."
    End

    Showln "Mail Sent!"

    // -----------------------------------------------------------
    // This is the MIME of the RSASSA-PSS signed email that was sent

    // 	MIME-Version: 1.0
    // 	Date: Thu, 20 Apr 2017 10:14:58 -0500
    // 	Message-ID: <3682A87344CB3A4FB5EB5BC9908C0C4DA01DA461@CHILKAT13>
    // 	Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha256;
    // 	 boundary="------------050103020705000601010800"
    // 	X-Priority: 3 (Normal)
    // 	Subject: Sample RSASSA-PSS Signed Email
    // 	From: support@chilkatsoft.com
    // 	To: "Chilkat Support" <support@chilkatsoft.com>,
    // 	 "Chilkat GMail" <chilkat.support@gmail.com>
    // 
    // 	--------------050103020705000601010800
    // 	Content-Type: text/plain; format=flowed
    // 	Content-Transfer-Encoding: 7bit
    // 
    // 	Sample RSASSA-PSS Signed Email
    // 	--------------050103020705000601010800
    // 	Content-Transfer-Encoding: base64
    // 	Content-Type: application/pkcs7-signature; name="smime.p7s"
    // 	Content-Disposition: attachment; filename="smime.p7s"
    // 
    // 	MIIG5wYJKoZIhvcNAQcCoIIG2DCCBtQCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg
    // 	ggL4MIIC9DCCAl2gAwIBAgIJAMPsJCT11cniMA0GCSqGSIb3DQEBCwUAMIGSMQswCQYDVQQGEwJB
    // 	VTERMA8GA1UECAwIVmljdG9yaWExEjAQBgNVBAcMCU1lbGJvdXJuZTEhMB8GA1UECgwYSW50ZXJu
    // 	ZXQgV2lkZ2l0cyBQdHkgTHRkMQ8wDQYDVQQDDAZXaWRnZXQxKDAmBgkqhkiG9w0BCQEWGWFkbWlu
    // 	QGludGVybmV0d2lkZ2V0cy5jb20wHhcNMTYxMTAxMTY1MjMyWhcNMjExMDMxMTY1MjMyWjCBkjEL
    // 	MAkGA1UEBhMCQVUxETAPBgNVBAgMCFZpY3RvcmlhMRIwEAYDVQQHDAlNZWxib3VybmUxITAfBgNV
    // 	BAoMGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEPMA0GA1UEAwwGV2lkZ2V0MSgwJgYJKoZIhvcN
    // 	AQkBFhlhZG1pbkBpbnRlcm5ldHdpZGdldHMuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKB
    // 	gQDGIdoCjyavs+F/Rm0VIB4m6O7VL1j+1IqieoR9NEX2GQvu2VCdceyxf9qaw1bxipEvjLwUkw7M
    // 	e+BTlL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ESMBAGA1UEBwwJTWVsYm91cm5lMSEwHwYDVQQKDBhJbnRlcm5ldCBX
    // 	aWRnaXRzIFB0eSBMdGQxDzANBgNVBAMMBldpZGdldDEoMCYGCSqGSIb3DQEJARYZYWRtaW5AaW50
    // 	ZXJuZXR3aWRnZXRzLmNvbQIJAMPsJCT11cniMIGzBgsqhkiG9w0BCRACCzGBo6CBoDCBkjELMAkG
    // 	A1UEBhMCQVUxETAPBgNVBAgMCFZpY3RvcmlhMRIwEAYDVQQHDAlNZWxib3VybmUxITAfBgNVBAoM
    // 	GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEPMA0GA1UEAwwGV2lkZ2V0MSgwJgYJKoZIhvcNAQkB
    // 	FhlhZG1pbkBpbnRlcm5ldHdpZGdldHMuY29tAgkAw+wkJPXVyeIwPQYJKoZIhvcNAQEKMDCgDTAL
    // 	BglghkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAIBogMCASAEgYCDQpT6vJZ9zERJ
    // 	JVX69PGUfCN5Eq9pKzoOTQSrIBe1YgNDSPd5pyOPP2MN1RpI0T/GTQZw4iWy5LZq0T5sjmk3fFVB
    // 	+VZjKtkTuhGaCdzMQXomVLBbI2fN4UaA4v1/Ayrqr8SY9Rsa20TpKv/bufK7oYs083UOtlcA1EHY
    // 	41wQ5A==
    // 
    // 	--------------050103020705000601010800--


End_Procedure

 

© 2000-2024 Chilkat Software, Inc. All Rights Reserved.