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
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
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
Secrets
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) Decrypt 256-bit AES GCM Produced by Something Unknown

Demonstrates how to decrypt something produced elsewhere (unknown) with 256-bit AES GCM.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-win32.pkg

Procedure Test
    String sKeyBase64
    String sIvBase64Url
    String sCipherBase64Url
    Handle hoCrypt
    Boolean iSuccess
    Handle hoBdEncrypted
    Handle hoBdAuthTag
    Integer iNumBytes
    String sAuthTagHex
    String sOriginalText
    String sTemp1
    Boolean bTemp1

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

    // We have the following to decrypt:

    // Key (Base64): 
    Move "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" To sKeyBase64

    // IV (Base64Url):
    Move "xrvaINMLqotAbWRK" To sIvBase64Url

    // ciphertext (base64url):
    Move "RtGNAS-zQOxSB8W0HfqJjCoyt9KgImW_l-HjVC40hOOl-RNfRF3hzDIT1kvFVF8i_KX9XmqAftb6lyq-jLCEc_MSgqt3q1ixv3Ez4SbS3G5e3qGzLwxIMi2sCt00aDNwK2ipsJ4aw8s7ePPnl4oY-y1st9rwCWR0rrgEZwS9jmS4uJWGPn9K3jbKRnMslznDbtFLNJctMVXBTP-cv47JelxLCBOQSlK29rMuEFrhHR_VQrPq6gtZaBVSXZSYT0XOklp7nu9mVhrMCRtBCC5oiu5MPE5JYx4ANo3hUY7_NyQl2bpn9GfRXrdvqRGE-gy2upj-cDkm0t_tV8xmYge9DBQTH3B_4BGl2qTk_o-m7pEmKkS8XSdQhGcuFlykqrkE8SzB5I8esfzWOM0pwxbz0H_VaylKYHY=" To sCipherBase64Url

    Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt
    If (Not(IsComObjectCreated(hoCrypt))) Begin
        Send CreateComObject of hoCrypt
    End

    Set ComCryptAlgorithm Of hoCrypt To "aes"
    Set ComCipherMode Of hoCrypt To "gcm"
    Set ComKeyLength Of hoCrypt To 256

    Get ComSetEncodedAad Of hoCrypt "random" "ascii" To iSuccess
    Send ComSetEncodedKey To hoCrypt sKeyBase64 "base64"
    Send ComSetEncodedIV To hoCrypt sIvBase64Url "base64url"

    // The cipher text contains the 16-byte auth tag at the end.
    // get it separately..
    Get Create (RefClass(cComChilkatBinData)) To hoBdEncrypted
    If (Not(IsComObjectCreated(hoBdEncrypted))) Begin
        Send CreateComObject of hoBdEncrypted
    End
    Get Create (RefClass(cComChilkatBinData)) To hoBdAuthTag
    If (Not(IsComObjectCreated(hoBdAuthTag))) Begin
        Send CreateComObject of hoBdAuthTag
    End
    Get ComAppendEncoded Of hoBdEncrypted sCipherBase64Url "base64url" To iSuccess

    Get ComNumBytes Of hoBdEncrypted To iNumBytes
    Get ComGetEncodedChunk Of hoBdEncrypted (iNumBytes - 16) 16 "hex" To sAuthTagHex

    Showln "Auth tag in hex: " sAuthTagHex

    Get ComAppendEncoded Of hoBdAuthTag sAuthTagHex "hex" To iSuccess
    Get ComRemoveChunk Of hoBdEncrypted (iNumBytes - 16) 16 To iSuccess

    // Use this special value to tell Chilkat to ignore the auth tag.
    Get ComSetEncodedAuthTag Of hoCrypt "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" "hex" To iSuccess

    // Decrypt
    Set ComEncodingMode Of hoCrypt To "base64"
    Get ComGetEncoded Of hoBdEncrypted "base64" To sTemp1
    Get ComDecryptStringENC Of hoCrypt sTemp1 To sOriginalText
    Get ComLastMethodSuccess Of hoCrypt To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoCrypt To sTemp1
        Showln sTemp1
    End
    Else Begin
        Showln sOriginalText
        Showln "Success."
    End

    // Decrypted text


End_Procedure

 

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