Code example C for password encryption and decryption in the program

Source: Internet
Author: User

Code example C for password encryption and decryption in the program

Question proposal

In actual software projects, password processing is often involved, such as user logon password, database password, and FTP password. To increase software flexibility, you generally need to put these passwords in a configuration file. However, the original password is easy to record. If the password is obtained by software intruders, the consequences are unimaginable. Therefore, we cannot directly enter the original password in the configuration file. Instead, we need to encrypt the password first, then enter the encrypted ciphertext in the configuration file, and decrypt it after the program reads the configuration.

The entire process 1 is shown.

Figure 1 Overall encryption and decryption process

 

Sample procedure

To demonstrate the entire encryption and decryption process, a demo program is designed. The execution process is shown in step 2.

Figure 2 sample procedure

 

Sample Code

 

 

Configuration File example

The configuration file is named Config. ini, as shown in figure 3.

Figure 3 Configuration File Content

 

Program Execution result

1. When iDecryptFlag is 0:

Result 4:

Figure 4 execution result when iDecryptFlag is 0

View the configuration file. The password value is the encrypted ciphertext.

 

2. When iDecryptFlag is 1:

Result 5:

Figure 5 execution result when iDecryptFlag is 1

View the configuration file. The password value goes through the process of "original text --> ciphertext --> original text.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.