Protect your files using Win32API functions
In the process of program development, often encountering the case where user information and private data are not stealing by others, that is, to encrypt data. Before Win2000, you want to encrypt and decrypt your data, usually use the CryptAPI function, quite cumbersome. Fortunately, from Win2000, the operating system provides functions to encrypt and decrypt files at the kernel, and is quite simple to use.
The encrypted function is Bool EncryptFile (LPCTSTSTSTSTSTO);
The parameter lpfilename can be a file name or a directory name. If it is a directory name, then the file created in this directory will be automatically encrypted. If the function is successful, a non-zero value will be returned, otherwise, the return value is zero, and the error code can be obtained via the getLastError () function.
The decryption function is BOOL DECRYPTFILE (LPCTSTSTR LPFILENAME, // to decrypt file name or directory name DWORD DWRESERVED / / reserved parameters must be 0);
Parameters LPFileName If it is a directory name, all files in this directory will be decrypted and the file created in this directory will not be automatically encrypted. If the function is successful, a non-zero value will be returned, otherwise, the return value is zero, and the error code can be obtained via the getLastError () function.
These two functions actually give the file system and Windows system accounts. After the user encrypts the file, you can still view it (you don't need to decrypt first); however, other users with the same permissions cannot be viewed, when they open When you add a secret file, you will get a warning message for "Reject Access". Also note that users (super administrators) (super administrators) are high than your privilege level, can still view your files at will.
Below is a small example of example, after compiling the program, you can encrypt the encrypted decryption operation by the command line.
//Encryptfile.exe
#include "windows.h" void print_USAGE () {Printf ("Usage: Encrypt