eHow launches Android app: Get the best of eHow on the go.

How To

How to Use Encryption Algorithms in Visual C++

Contributor
By eHow Contributing Writer

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.

Difficulty: Moderately Challenging
Instructions
  1. Step 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. Step 2

    Open Visual C++ on your programming workstation and create a new file called encrypt.cpp.

  3. Step 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. Step 4

    Create a void function called RunEncryption().

  5. Step 5

    Initialize a new CkCrypt2 object. The syntax for this is:
    CkCrypt2 myEncrypt;

  6. Step 6

    Establish public key encryption. Call this put_CryptAlgorithm with the following syntax:
    myEncrypt.put_CryptAlgorithm("pki");

  7. Step 7

    Initialize a new Certificate object. Use the following syntax:
    CkCert myCertificate;

  8. Step 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. Step 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. Step 10

    Compile encrypt.cpp in Visual C++. If the compile is successful, execute this program to test it out.

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.
Subscribe

Post a Comment

Post a Comment

Related Ads

  • Have you done this? Click here to let us know.
I Did This
Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

eHow Computers
eHow_eHow Technology and Electronics