(C) Example: Crypt2.EncryptEncoded method
Demonstrates how to call the EncryptEncoded method.
#include <C_CkCrypt2.h>
void ChilkatSample(void)
{
HCkCrypt2 crypt;
const char *encrypted;
const char *decrypted;
crypt = CkCrypt2_Create();
CkCrypt2_putCryptAlgorithm(crypt,"aes");
CkCrypt2_putCipherMode(crypt,"cbc");
CkCrypt2_putKeyLength(crypt,128);
CkCrypt2_SetEncodedKey(crypt,"000102030405060708090A0B0C0D0E0F","hex");
CkCrypt2_SetEncodedIV(crypt,"000102030405060708090A0B0C0D0E0F","hex");
// Encrypt the bytes 0x00, 0x01, 0x02, ... 0x0A
// and return the encrypted bytes using the lowercase hex encoding.
CkCrypt2_putEncodingMode(crypt,"hex_lower");
encrypted = CkCrypt2_encryptEncoded(crypt,"000102030405060708090a");
printf("%s\n",encrypted);
// Output:
// 9da2ae71a5378487114b430e5e230378
decrypted = CkCrypt2_decryptEncoded(crypt,encrypted);
printf("%s\n",decrypted);
// Output:
// 000102030405060708090a
CkCrypt2_Dispose(crypt);
}
|