(C) Transition from RandomizeKey to GenRandomBytesENC
Provides instructions for replacing deprecated RandomizeKey method calls with GenRandomBytesENC. Note: This example requires Chilkat v11.0.0 or greater.
#include <C_CkCrypt2.h>
void ChilkatSample(void)
{
HCkCrypt2 crypt;
const char *randomKeyBase64;
crypt = CkCrypt2_Create();
CkCrypt2_putCryptAlgorithm(crypt,"aes");
CkCrypt2_putCipherMode(crypt,"cbc");
CkCrypt2_putKeyLength(crypt,256);
// ...
// ------------------------------------------------------------------------
// The RandomizeKey method is deprecated:
// Generates and sets a random 32-byte (256-bit) secret key.
CkCrypt2_RandomizeKey(crypt);
// ------------------------------------------------------------------------
// Do the equivalent using GenRandomBytesENC followed by SetEncodedKey
CkCrypt2_putEncodingMode(crypt,"base64");
randomKeyBase64 = CkCrypt2_genRandomBytesENC(crypt,32);
CkCrypt2_SetEncodedKey(crypt,randomKeyBase64,"base64");
CkCrypt2_Dispose(crypt);
}
|