How to Use Encryption Algorithms in Visual C++
It is fairly easy to use encryption algorithms in visual C++. The most common approach is to use public key encryption with a digital certificate. To accomplish this, all you need is to have access to the Chilkat C++ encryption algorithm library.
Instructions
-
-
1
Determine if the Chilkat C++ algorithm is available on your Windows programming workstation. If it isn't, then go the World Wide Web to download it.
-
2
Open Visual C++ on your programming workstation and create a new file called encrypt.cpp.
-
-
3
Load the header files CkCrypt.2 and CkCert.h at the top of this file. This can be accomplished using the following syntax:
#include
#include -
4
Create a void function called RunEncryption().
-
5
Initialize a new CkCrypt2 object. The syntax for this is:
CkCrypt2 myEncrypt; -
6
Establish public key encryption. Call this put_CryptAlgorithm with the following syntax:
myEncrypt.put_CryptAlgorithm("pki"); -
7
Initialize a new Certificate object. Use the following syntax:
CkCert myCertificate; -
8
Load your digital certificate from a file. This can be done use the LoadFromFile function. We will assume that this certificate is called sample.cert.
myCertificate.LoadFromFile("sample.cert"); -
9
Encrypt the file using the CkEncryptFile function. Assume that the data you want to encrypt is in the file named fileToEncrypt.txt. Use the following syntax:
myEncrypt.CkEncryptFile("fileToEncrypt.txt"); -
10
Compile encrypt.cpp in Visual C++. If the compile is successful, execute this program to test it out.
-
1
Tips & Warnings
If you have compilation errors, check for missing semicolons.
Decrypting a file is easy using the CkDecryptFile function.
Keep your digital certificate in a safe place. This is required for decrypting the file.