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) Duplicate Java AES Results

Demonstrates how to duplicate Java code for AES encryption.

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>

void ChilkatSample(void)
    {
    HCkCrypt2W crypt;
    const wchar_t *encrypted;

    crypt = CkCrypt2W_Create();

    CkCrypt2W_putCryptAlgorithm(crypt,L"aes");
    CkCrypt2W_putCipherMode(crypt,L"cbc");
    CkCrypt2W_putKeyLength(crypt,256);

    CkCrypt2W_SetEncodedIV(crypt,L"000102030405060708090A0B0C0D0E0F",L"hex");
    CkCrypt2W_SetEncodedKey(crypt,L"uX1AytOx2bqKn1G1NiblFM3YrEMnvciC",L"ascii");

    CkCrypt2W_putEncodingMode(crypt,L"hex");

    encrypted = CkCrypt2W_encryptStringENC(crypt,L"tmpString");
    wprintf(L"%s\n",encrypted);

    wprintf(L"%s\n",CkCrypt2W_decryptStringENC(crypt,encrypted));

    // The above Chilkat code duplicates the following Java code:

    // import javax.crypto.Cipher;
    // import javax.crypto.spec.IvParameterSpec;
    // import javax.crypto.spec.SecretKeySpec;
    // 
    // public class Test {
    // 	private static final String KEY = "uX1AytOx2bqKn1G1NiblFM3YrEMnvciC";
    // 	private static final String IV = "000102030405060708090A0B0C0D0E0F";
    // 
    // 	private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
    // 	public static String bytesToHex(byte[] bytes) {
    // 	    char[] hexChars = new char[bytes.length * 2];
    // 	    for (int j = 0; j < bytes.length; j++) {
    // 	        int v = bytes[j] & 0xFF;
    // 	        hexChars[j * 2] = HEX_ARRAY[v >>> 4];
    // 	        hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
    // 	    }
    // 	    return new String(hexChars);
    // 	}
    // 	public static byte[] hexToBytes(String s) {
    // 	    int len = s.length();
    // 	    byte[] data = new byte[len / 2];
    // 	    for (int i = 0; i < len; i += 2) {
    // 	        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
    // 	                             + Character.digit(s.charAt(i+1), 16));
    // 	    }
    // 	    return data;
    // 	}
    // 	public static byte[] encrypt(String value) {
    // 		try {
    // 			System.out.println("---- encrypt ----");
    // 			IvParameterSpec iv = new IvParameterSpec(hexToBytes(IV));
    // 			SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("ASCII"), "AES");
    // 			Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    // 			cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
    // 			byte[] encrypted = cipher.doFinal(value.getBytes("ASCII"));
    // 			String x = bytesToHex(encrypted);
    // 			System.out.println(x);
    // 			return encrypted;
    // 		} catch (Exception ex) {
    // 			ex.printStackTrace();
    // 			return null;
    // 		}
    // 	}
    // 
    // 	public static String decrypt(byte[] encrypted) {
    // 		try {
    // 			System.out.println("---- decrypt ----");
    // 			IvParameterSpec iv = new IvParameterSpec(hexToBytes(IV));
    // 			SecretKeySpec skeySpec = new SecretKeySpec(KEY.getBytes("ASCII"), "AES");
    // 			Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
    // 			cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
    // 			byte[] original = cipher.doFinal(encrypted);
    // 			String x = new String(original);
    // 			System.out.println(x);
    // 			return x;
    // 		} catch (Exception ex) {
    // 			ex.printStackTrace();
    // 			return null;
    // 		}
    // 
    // 	}
    // 
    // 	public static void main(String[] args) {
    // 		byte[] encrypted = encrypt("tmpString");
    // 		decrypt(encrypted);
    // 	}
    // }
    // 


    CkCrypt2W_Dispose(crypt);

    }

 

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