Chilkat Examples

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

Visual FoxPro Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
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
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
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Visual FoxPro) RSASSA-PSS Sign Binary Data

Signs binary data to create a PKCS7/CMS signature. The signature algorithm is RSASSA-PSS with SHA256.

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

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

LOCAL loCrypt
LOCAL loPfx
LOCAL lnSuccess
LOCAL loCert
LOCAL loBinaryData
LOCAL lcPkcs7sig

*  This example requires the Chilkat Crypt API to have been previously unlocked.
*  See Unlock Chilkat Crypt for sample code.

loCrypt = CreateObject('Chilkat_9_5_0.Crypt2')

*  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.)
loPfx = CreateObject('Chilkat_9_5_0.Pfx')
lnSuccess = loPfx.LoadPfxFile("qa_data/rsassa-pss/privatekey.pfx","PFX_PASSWORD")
IF (lnSuccess <> 1) THEN
    ? loPfx.LastErrorText
    RELEASE loCrypt
    RELEASE loPfx
    CANCEL
ENDIF

*  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.)
loCert = loPfx.GetCert(0)
IF (loPfx.LastMethodSuccess <> 1) THEN
    ? loPfx.LastErrorText
    RELEASE loCrypt
    RELEASE loPfx
    CANCEL
ENDIF

loCrypt.SetSigningCert(loCert)

*  Indicate that RSASSA-PSS with SHA256 should be used.
loCrypt.SigningAlg = "pss"
loCrypt.HashAlgorithm = "sha256"

loCrypt.EncodingMode = "base64_mime"

*  Load a binary file to be signed:
loBinaryData = CreateObject('Chilkat_9_5_0.BinData')
lnSuccess = loBinaryData.LoadFile("qa_data/jpg/starfish20.jpg")
IF (lnSuccess <> 1) THEN
    ? "Failed to load file."
    RELEASE loCert
    RELEASE loCrypt
    RELEASE loPfx
    RELEASE loBinaryData
    CANCEL
ENDIF

*  Sign the binary bytes to get a PKCS7 detached signature in base64 format:
lcPkcs7sig = loCrypt.SignBdENC(loBinaryData)
? "Detached PCKS7 Signature:"
? lcPkcs7sig

*  This signature looks like this:

*  MIIG5wYJKoZIhvcNAQcCoIIG2DCCBtQCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0B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CgDTAL
*  BglghkgBZQMEAgGhGjAYBgkqhkiG9w0BAQgwCwYJYIZIAWUDBAIBogMCASAEgYCWV0g82volvnwf
*  YpwIpqpQzMmTPBKNQmFGjbyH2opdcbJwgu2qEFvaXkyjYDtgQ7XsCqc15dm6Ee1Ujkosbp57kLTt
*  /WbwxY1CC/uxs3oV+5ESUyB+2iocTYABYn4ye0FhBPut86n/gzZTL+RLG6Z1fxwwzkoxWUp7GjKK
*  58mveQ==

*  The ASN.1 of the signature can be examined by browsing to https://lapo.it/asn1js/ ,
*  then copy-and-paste the Base64 signature into the form and decode..

*  The signature can be verified against the original data like this:
lnSuccess = loCrypt.VerifyBdENC(loBinaryData,lcPkcs7sig)
? "Signature verified: " + STR(lnSuccess)

*  Now we'll create an opaque signature (the opposite of a detached signature).
*  An opaque signature is a PKCS7/CMS message that contains both the original data and
*  the signature.  The verification process extracts the original data.

*  Then OpaqueSignBd method in-place signs the binaryData.
*  The contents of binaryData are replaced with the CMS/PKCS7 message.
lnSuccess = loCrypt.OpaqueSignBd(loBinaryData)

*  Show the contents of the opaque signature in base64 format:
? "Opaque Signature:"
? loBinaryData.GetEncoded("base64_mime")

*  MIIKCgYJKoZIhvcNAQcCoIIJ+zCCCfcCAQExDzANBglghkgBZQMEAgEFADCCAywGCSqGSIb3DQEH
*  AaCCAx0EggMZ/9j/4AAQSkZJRgABAQEASABIAAD//gAmRmlsZSB3cml0dGVuIGJ5IEFkb2JlIFBo
*  b3Rvc2hvcD8gNC4w/9sAQwAQCwwODAoQDg0OEhEQExgoGhgWFhgxIyUdKDozPTw5Mzg3QEhcTkBE
*  V0U3OFBtUVdfYmdoZz5NcXlwZHhcZWdj/9sAQwEREhIYFRgvGhovY0I4QmNjY2NjY2NjY2NjY2Nj
*  Y2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2Nj/8IAEQgAFAAUAwERAAIRAQMRAf/E
*  ABcAAAMBAAAAAAAAAAAAAAAAAAIDBAX/xAAYA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0xNzA0MjkxNjEwMjZaMC8GCSqGSIb3
*  DQEJBDEiBCCuNRCSgx4FhSGYMaM+DXjtbJsXTDYsBjoX4iHqodQwHzBfBgkqhkiG9w0BCQ8xUjBQ
*  MAsGCWCGSAFlAwQBAjAKBggqhkiG9w0DBzAOBggqhkiG9w0DAgICAIAwDQYIKoZIhvcNAwICAUAw
*  BwYFKw4DAgcwDQYIKoZIhvcNAwICASgwgbEGCSsGAQQBgjcQBDGBozCBoDCBkjELMAkGA1UEBhMC
*  QVUxETAPBgNVBAgMCFZpY3RvcmlhMRIwEAYDVQQHDAlNZWxib3VybmUxITAfBgNVBAoMGEludGVy
*  bmV0IFdpZGdpdHMgUHR5IEx0ZDEPMA0GA1UEAwwGV2lkZ2V0MSgwJgYJKoZIhvcNAQkBFhlhZG1p
*  bkBpbnRlcm5ldHdpZGdldHMuY29tAgkAw+wkJPXVyeIwgbMGCyqGSIb3DQEJEAILMYGjoIGgMIGS
*  MQswCQYDVQQGEwJBVTERMA8GA1UECAwIVmljdG9yaWExEjAQBgNVBAcMCU1lbGJvdXJuZTEhMB8G
*  A1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMQ8wDQYDVQQDDAZXaWRnZXQxKDAmBgkqhkiG
*  9w0BCQEWGWFkbWluQGludGVybmV0d2lkZ2V0cy5jb20CCQDD7CQk9dXJ4jA9BgkqhkiG9w0BAQow
*  MKANMAsGCWCGSAFlAwQCAaEaMBgGCSqGSIb3DQEBCDALBglghkgBZQMEAgGiAwIBIASBgAGVtpI5
*  slxfw+1EyJK4jqxokLvUrqksBLotv1vaP4QaSeF2A1lNrsPfJoEjZJpD1F6vXrFPsR4sPD+6n7P/
*  lz3sGoFykTjE2rPwKEFIbzfxD3gSZKJPWFgDa19DojarmwJMkSPXt9TQEzdjDPrbsCGLYOy29Puq
*  ZDI1rUcyxg7Y

*  The ASN.1 of the signature can be examined by browsing to https://lapo.it/asn1js/ ,
*  then copy-and-paste the Base64 signature into the form and decode..

*  The signature is verified, and the original data restored like this:
lnSuccess = loCrypt.OpaqueVerifyBd(loBinaryData)
IF (lnSuccess <> 1) THEN
    ? "Signature verification failed."
    ? loCrypt.LastErrorText
    RELEASE loCert
    RELEASE loCrypt
    RELEASE loPfx
    RELEASE loBinaryData
    CANCEL
ENDIF

*  Save the extracted data to a file:
lnSuccess = loBinaryData.WriteFile("qa_output/extractedStarfish20.jpg")

? "Signature verified."

RELEASE loCert

RELEASE loCrypt
RELEASE loPfx
RELEASE loBinaryData


 

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