Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Visual Basic 6.0 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
Cert Store
Certificates
Cloud Signature CSC
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
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
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
X
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

(Visual Basic 6.0) Create PEM-encoded PKCS#7 Detached Signature

See more Digital Signatures Examples
Demonstrates how to create a PKCS7 PEM-encoded object containing a detached signature.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

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

Dim cert As New ChilkatCert

' Load the cert and private key.
Dim success As Long
success = cert.LoadPfxFile("qa_data/pfx/myCertAndKey.p12","password")
If (success <> 1) Then
    Debug.Print cert.LastErrorText
    Exit Sub
End If

Dim crypt As New ChilkatCrypt2

success = crypt.SetSigningCert(cert)
If (success <> 1) Then
    Debug.Print crypt.LastErrorText
    Exit Sub
End If

' Use SHA-256
crypt.HashAlgorithm = "sha256"

' Hash the utf-8 byte representation of the string
crypt.Charset = "utf-8"

' Return the result in base64
crypt.EncodingMode = "base64Mime"

' Sign some text to create a detached signature (i.e. a signature that does not include the signed data)
Dim textToSign As String
textToSign = "This is the text to be hashed and signed."
Dim sigBase64 As String
sigBase64 = crypt.SignStringENC(textToSign)
If (crypt.LastMethodSuccess <> 1) Then
    Debug.Print crypt.LastErrorText
    Exit Sub
End If

Debug.Print sigBase64

' The result:

' MIIWbgYJKoZIhvcNAQcCoIIWXzCCFlsCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg
' ghMXMIIFuzCCA6OgAwIBAgIIVwoRl0LE48wwDQYJKoZIhvcNAQELBQAwazELMAkGA1UEBhMCSVQx
' ...
' ...

' If we want it in PEM format with just LF line-endings:
Dim sb As New ChilkatStringBuilder
' Just LF line endings, not CRLF.
Dim crlf As Long
crlf = 0
success = sb.AppendLine("-----BEGIN PKCS7-----",crlf)
success = sb.Append(sigBase64)
success = sb.AppendLine("-----END PKCS7-----",crlf)
success = sb.ToLF()

' Save to a file.
success = sb.WriteFile("c:/temp/qa_output/sig.pem","utf-8",0)

' Examine..
Debug.Print sb.GetAsString()

' Result is:

' -----BEGIN PKCS7-----
' MIIWbgYJKoZIhvcNAQcCoIIWXzCCFlsCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg
' ghMXMIIFuzCCA6OgAwIBAgIIVwoRl0LE48wwDQYJKoZIhvcNAQELBQAwazELMAkGA1UEBhMCSVQx
' DjAMBgNVBAcMBU1pbGFuMSMwIQYDVQQKDBpBY3RhbGlzIFMucC5BLi8wMzM1ODUyMDk2NzEnMCUG
' A1UEAwweQWN0YWxpcyBBdXRoZW50aWNhdGlvbiBSb290IENBMB4XDTExMDkyMjExMjIwMloXDTMw
' MDkyMjExMjIwMlowazELMAkGA1UEBhMCSVQxDjAMBgNVBAcMBU1pbGFuMSMwIQYDVQQKDBpBY3Rh
' bGlzIFMucC5BLi8wMzM1ODUyMDk2NzEnMCUGA1UEAwweQWN0YWxpcyBBdXRoZW50aWNhdGlvbiBS
' b290IENBMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAp8bEpSmkLO/lGMWwUKNvUTuf
' ClrJwkg4CsIcoBh/kbWHuUA/3R1oHwiD1S0eiKD4j1aPbZkCkpAW1V8IbInX4ay8IMKx4INRimlN
' AJZaby/ARH6jDuSRzVju3PvHHkVH3Se5CAGfpiEd9UEtL0z9KK3giq0itFZljoZUj5NDKd45Rnij
' MCO6zfB9E1fAXdKDa0hMxKufgFpbOr3JpyI/gCczWw63igxdBzcIy2zSekciRDXFzMwujt0q7bd9
' ...
' ...
' -----END PKCS7-----

 

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