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

PowerBuilder 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

 

 

 

(PowerBuilder) Encrypt MIME using RSAES-OAEP with SHA256 and AES-128 content encryption

Demonstrates how to encrypt MIME using RSAES-OAEP with SHA256 and AES-128 content encryption.

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
integer li_Success
oleobject loo_Mime
oleobject loo_Part0
oleobject loo_Part1
oleobject loo_SbMime
oleobject loo_Cert

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

loo_Mime = create oleobject
li_rc = loo_Mime.ConnectToNewObject("Chilkat_9_5_0.Mime")
if li_rc < 0 then
    destroy loo_Mime
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// Create a MIME message to encrypt.
loo_Mime.NewMultipartMixed()
loo_Mime.AddHeaderField("someHeader1","Some value 1")
loo_Mime.AddHeaderField("someHeader2","Some value 2")

loo_Part0 = create oleobject
li_rc = loo_Part0.ConnectToNewObject("Chilkat_9_5_0.Mime")

loo_Part0.AddHeaderField("hdrA","Some value A")
loo_Part0.AddHeaderField("hdrB","Some value B")
loo_Part0.ContentType = "text/plain"
loo_Part0.SetBody("This is the plain-text body.")

loo_Part1 = create oleobject
li_rc = loo_Part1.ConnectToNewObject("Chilkat_9_5_0.Mime")

loo_Part1.AddHeaderField("hdrX","Some value X")
loo_Part1.AddHeaderField("hdrY","Some value Y")
loo_Part1.ContentType = "text/xml"
loo_Part1.SetBody("<a>This is the XML body</a>")

loo_Mime.AppendPart(loo_Part0)
loo_Mime.AppendPart(loo_Part1)

// The MIME to be encrypted:
loo_SbMime = create oleobject
li_rc = loo_SbMime.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_Mime.GetMimeSb(loo_SbMime)
Write-Debug loo_SbMime.GetAsString()

// 	Content-Type: multipart/mixed; boundary="------------080303020600020604010008"
// 	someHeader1: Some value 1
// 	someHeader2: Some value 2
// 
// 	--------------080303020600020604010008
// 	hdrA: Some value A
// 	hdrB: Some value B
// 	Content-Type: text/plain
// 
// 	This is the plain-text body.
// 	--------------080303020600020604010008
// 	hdrX: Some value X
// 	hdrY: Some value Y
// 	Content-Type: text/xml
// 
// 	<a>This is the XML body</a>
// 	--------------080303020600020604010008--
// 

// Load an RSA-based certificate.
// (Encrypting MIME only requires the public key.  Decrypting MIME requires the private key.)
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat_9_5_0.Cert")

li_Success = loo_Cert.LoadFromFile("qa_data/rsaes-oaep/cert.pem")
if li_Success <> 1 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Mime
    destroy loo_Part0
    destroy loo_Part1
    destroy loo_SbMime
    destroy loo_Cert
    return
end if

// Set the email object properties to indicate the desired encryption.
loo_Mime.Pkcs7CryptAlg = "aes"
// If AES-256 is desired, set the following property to 256.
loo_Mime.Pkcs7KeyLength = 128
loo_Mime.OaepPadding = 1
// Other choices for the OAEP hash algorithm are "sha1", "sha384", and "sha512"
loo_Mime.OaepHash = "sha256"

// Encrypt the MIME (to create S/MIME, which stands for "Secure MIME")
li_Success = loo_Mime.Encrypt(loo_Cert)
if li_Success <> 1 then
    Write-Debug loo_Mime.LastErrorText
    destroy loo_Mime
    destroy loo_Part0
    destroy loo_Part1
    destroy loo_SbMime
    destroy loo_Cert
    return
end if

Write-Debug "---------------"
Write-Debug "Encrypted MIME:"
Write-Debug "---------------"
Write-Debug loo_Mime.GetMime()

Write-Debug "Success."

// ---------------------------------------------------
// This is sample output for RSAES-OAEP encrypted MIME:
// ---------------------------------------------------

// Content-Type: application/x-pkcs7-mime; name="smime.p7m"; smime-type="enveloped-data"
// someHeader1: Some value 1
// someHeader2: Some value 2
// Content-Disposition: attachment; filename="smime.p7m"
// Content-Transfer-Encoding: base64
// 
// MIIDvAYJKoZIhvcNAQcDoIIDrTCCA6kCAQAxggGgMIIBnAIBADB1MGgxCzAJBgNVBAYTAlVTMQsw
// CQYDVQQIDAJJTDEQMA4GA1UEBwwHV2hlYXRvbjEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ
// dHkgTHRkMRcwFQYDVQQDDA5DaGlsa2F0V2lkZ2V0cwIJA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XORPp5LhuZr5mf62YOXSSUwR5P0cXy4Rc+pN5lhRQPCf5z2


destroy loo_Mime
destroy loo_Part0
destroy loo_Part1
destroy loo_SbMime
destroy loo_Cert

 

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