The question is raised
In the actual software project, often involves the processing of the password, such as user login password, database password, ftp password and so on. In order to increase the flexibility of software, these passwords are generally required to be placed in a configuration file. But the original password is easy to record, if the software intruder access, the consequences will be unthinkable. Therefore, we can not directly fill in the original password into the configuration file, but first encrypt the password, and then fill in the encrypted ciphertext into the configuration file, and so the program read the configuration before the decryption process.
The entire process is shown in 1.
Figure 1 Adding and decrypting the overall process
Sample program Flow
In order to demonstrate the entire decryption process, a demo program is designed, which executes flow 2.
Figure 2 Sample program Flow
Sample program code
Configuration file Example
The configuration file is named Config.ini, which is set to 3.
Figure 3 Configuration file contents
Program execution Results
1. Idecryptflag is 0 o'clock:
The execution results are shown in 4:
Figure 4 Execution result of Idecryptflag to 0 o'clock
To view the configuration file, the password value is ciphertext after encryption.
2. Idecryptflag is 1 o'clock:
The execution results are shown in 5:
Figure 5 Execution result of Idecryptflag to 1 o'clock
Viewing the configuration file, the password value goes through the process of "text-to-text-to-source".
C code example for decrypting a password in a program