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

Unicode C 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
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

 

 

 

(Unicode C) AES-CMAC

Demonstrates using the AES-CMAC algorithm, which is a keyed hash function similar to HMAC and Poly1305.

Note: Chilkat added AES-CMAC in version 9.5.0.95.

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkCrypt2W.h>
#include <C_CkBinDataW.h>

void ChilkatSample(void)
    {
    HCkCrypt2W crypt;
    const wchar_t *keyHex;
    BOOL success;
    const wchar_t *messageBytes;
    HCkBinDataW bd;
    const wchar_t *cmac;
    const wchar_t *plainText;
    const wchar_t *encTag;

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

    crypt = CkCrypt2W_Create();

    // Set the MAC algorithm to AES-CMAC
    CkCrypt2W_putMacAlgorithm(crypt,L"aes-cmac");

    // AES-CMAC always uses a 16-byte (128-bit) MAC key.
    keyHex = L"2b7e151628aed2a6abf7158809cf4f3c";
    success = CkCrypt2W_SetMacKeyEncoded(crypt,keyHex,L"hex");

    // Let's compute the AES-CMAC for the test vector at https://www.rfc-editor.org/rfc/rfc4493#appendix-A
    // Here we have 64 bytes in hex representation.
    messageBytes = L"6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e5130c81c46a35ce411e5fbc1191a0a52eff69f2445df4f9b17ad2b417be66c3710";

    bd = CkBinDataW_Create();
    CkBinDataW_AppendEncoded(bd,messageBytes,L"hex");

    // Compute the AES-CMAC for the bytes contained in bd and return the AES-CMAC in hex representation.
    CkCrypt2W_putEncodingMode(crypt,L"hex_lower");
    cmac = CkCrypt2W_macBdENC(crypt,bd);
    wprintf(L"%s\n",cmac);
    // Output should be: 51f0bebf7e3b9d92fc49741779363cfe

    // Now do the same for a string:
    plainText = L"'Twas brillig, and the slithy toves\nDid gyre and gimble in the wabe:\nAll mimsy were the borogoves,\nAnd the mome raths outgrabe.";
    encTag = CkCrypt2W_macStringENC(crypt,plainText);
    wprintf(L"%s\n",encTag);

    // Output should be: 4fca1fcbd265048d247f99ab57fa3ceb


    CkCrypt2W_Dispose(crypt);
    CkBinDataW_Dispose(bd);

    }

 

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