Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

PowerBuilder Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(PowerBuilder) Duplicate OpenSSL smime Command

Demonstrates how to duplicate an OpenSSL smime command to sign a text file using cert + key.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

integer li_rc
string ls_CertPath
string ls_PrivateKeyPath
string ls_Password
string ls_DataFile
oleobject loo_Cert
integer li_Success
oleobject loo_PrivKey
oleobject loo_Bd
oleobject loo_Crypt
oleobject loo_SbPem

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

// This example duplicates the following OpenSSL command:
// 
// smime -sign -in helloWorld.txt -signer cert.pem -inkey my.key -passin pass:test1234 -outform PEM -out helloWorldSigned.pem

ls_CertPath = "qa_data/cert.pem"
ls_PrivateKeyPath = "qa_data/my.key"
ls_Password = "test1234"
ls_DataFile = "qa_data/helloWorld.txt"

loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat_9_5_0.Cert")
if li_rc < 0 then
    destroy loo_Cert
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Cert.LoadFromFile(ls_CertPath)
if li_Success <> 1 then
    Write-Debug loo_Cert.LastErrorText
    destroy loo_Cert
    return
end if

loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat_9_5_0.PrivateKey")

li_Success = loo_PrivKey.LoadEncryptedPemFile(ls_PrivateKeyPath,ls_Password)
if li_Success <> 1 then
    Write-Debug loo_PrivKey.LastErrorText
    destroy loo_Cert
    destroy loo_PrivKey
    return
end if

loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat_9_5_0.BinData")

li_Success = loo_Bd.LoadFile(ls_DataFile)
if li_Success <> 1 then
    Write-Debug "Failed to load " + ls_DataFile
    destroy loo_Cert
    destroy loo_PrivKey
    destroy loo_Bd
    return
end if

loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat_9_5_0.Crypt2")

li_Success = loo_Crypt.SetSigningCert2(loo_Cert,loo_PrivKey)
if li_Success <> 1 then
    Write-Debug loo_Crypt.LastErrorText
    destroy loo_Cert
    destroy loo_PrivKey
    destroy loo_Bd
    destroy loo_Crypt
    return
end if

li_Success = loo_Crypt.OpaqueSignBd(loo_Bd)
if li_Success <> 1 then
    Write-Debug loo_Crypt.LastErrorText
    destroy loo_Cert
    destroy loo_PrivKey
    destroy loo_Bd
    destroy loo_Crypt
    return
end if

loo_SbPem = create oleobject
li_rc = loo_SbPem.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_SbPem.AppendLine("-----BEGIN PKCS7-----",1)
loo_SbPem.Append(loo_Bd.GetEncoded("base64_mime"))
loo_SbPem.AppendLine("-----END PKCS7-----",1)
loo_SbPem.WriteFile("helloWorldSigned.pem","utf-8",0)

Write-Debug loo_SbPem.GetAsString()

// Sample output:

// -----BEGIN PKCS7-----
// MIINxAYJKoZIhvcNAQcCoIINtTCCDbECAQExCzAJBgUrDgMCGgUAMBoGCSqGSIb3DQEHAaANBAtI
// ZWxsbyBXb3JsZKCCC0owggYQMIID+KADAgECAhBNlCwQ1DvglAnFgS06KwZPMA0GCSqGSIb3DQEB
// DAUAMIGIMQswCQYDVQQGEwJVUzETMBEGA1UECBMKTmV3IEplcnNleTEUMBIGA1UEBxMLSmVyc2V5
// IENpdHkxHjAcBgNVBAoTFVRoZSBVU0VSVFJVU1QgTmV0d29yazEuMCwGA1UEAxMlVVNFUlRydXN0
// IFJTQSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0xODExMDIwMDAwMDBaFw0zMDEyMzEyMzU5
// NTlaMIGWMQswCQYDVQQGEwJHQjEbMBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQH
// EwdTYWxmb3JkMRgwFgYDVQQKEw9TZWN0aWdvIExpbWl0ZWQxPjA8BgNVBAMTNVNlY3RpZ28gUlNB
// IENsaWVudCBBdXRoZW50aWNhdGlvbiBhbmQgU2VjdXJlIEVtYWlsIENBMIIBIjANBgkqhkiG9w0B
// AQEFAAOCAQ8AMIIBCgKCAQEAyjztlApB/975Rrno1jvm2pK/KxBOqhq8gr2+JhwpKirSzZxQgT9t
// lC7zl6hn1fXjSo5MqXUfItMltrMaXqcESJuK8dtK56NCSrq4iDKaKq9NxOXFmqXX2zN8HHGjQ2b2
// Xv0v1L5Nk1MQPKA19xeWQcpGEGFUUd0kN+oHox+L9aV1rjfNiCj3bJk6kJaOPabPi2503nn/ITX5
// e8WfPn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IMYIC
// MzCCAi8CAQEwgawwgZYxCzAJBgNVBAYTAkdCMRswGQYDVQQIExJHcmVhdGVyIE1hbmNoZXN0ZXIx
// EDAOBgNVBAcTB1NhbGZvcmQxGDAWBgNVBAoTD1NlY3RpZ28gTGltaXRlZDE+MDwGA1UEAxM1U2Vj
// dGlnbyBSU0EgQ2xpZW50IEF1dGhlbnRpY2F0aW9uIGFuZCBTZWN1cmUgRW1haWwgQ0ECEQDwUrMy
// 4rq9PIFHeb0WvDbOMAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqG
// SIb3DQEJBTEPFw0xOTA0MDIyMjM2MjRaMCMGCSqGSIb3DQEJBDEWBBQKTVWo13jlAi+rcBl3xdhA
// u8SG0DANBgkqhkiG9w0BAQEFAASCAQAWaz5itTD7L3YUWuRS5nBzJKv6RUe84muwLICW+U5HEEd7
// aSNXCivMzsIYGN3VpBAfIGbRywDZ8SLFkmR3ernA4y0ki5SUNxfe6s3fsqPVIO56JEEF0/OZ54KU
// 6o/Tn2Qw8mYyYW5n2O690DGqtN/mZjI5vyRM8fG6KDrlnMplACF4St6XZx9Od/Znq039IPzgukJI
// rCIm9n0LFEdSYlajjS/d5GsIKWmy5ktrsXk5Ym6+Um95FBDuwrZyW1qYo+cLAWSBSf9poMUxwQNY
// EAA1iZqJjnlwsgMgM44h9voAW+wDMfcGFUwGDTxaLday6vqxHobR3MwjsBI8qjRbb28G
// -----END PKCS7-----
// 
// 


destroy loo_Cert
destroy loo_PrivKey
destroy loo_Bd
destroy loo_Crypt
destroy loo_SbPem

 

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