INI file encryption

Source: Internet
Author: User

The INI file seems to have come out of the stage under the powerful XML attack, but in some simple settings and storage, using the INI file is still a good choice.
For example, to save the song list, username, and password, the world browser also seems to use INI to save a lot of information. Sometimes we do not want ini information to be seen by others, you need to encrypt it.

Below, Xiao Peng will discuss this topic.
The idea is to encode the content to be written into ini so that the content of the INI file is garbled,
When the program needs to read the content of the INI file, it is decoded and then read, and the encoding and decoding algorithm is only known to the programmer, so the information of the INI file is secure.

The detailed process is as follows:
For example, the executable program xiaosi.exe and the configuration file xiaosi. ini are both located in C: chatang, and the content of xiaosi. INI is garbled.
When xiaosi.exe is run, the program creates another configuration file sIgE. ini under C: windowssystem32 (of course, only one programmer knows this location and file name ),
And decompress xiaosi.inito store the content in sige.ini. Then, xiaosi.exe performs all read and write operations on the ini configuration file on SiGe. ini,
When the xiaosi.exe program exits, write the content encoding of SiGe. ini to xiaosi. ini, and then delete sIgE. ini.

Next we will talk about the so-called CODEC algorithm (in fact, it is just a small computation that does not involve calculation ).
We know that (a xor B) xor B = a XOR (B xor B) = a XOR 0 =
Therefore, we assume that A is the content of SiGe. ini,
B is a random number, and a xor B is garbled. We write it into the file xiaosi. ini,
When reading the file, take xiaosi again. the content of INI is a xor B, and then performs a different or operation from B. (a xor B) xor B = A, writes a to sIgE. INI, which completes the decoding operation.

The code is written below.
Dim filename1 as string 'first File
Dim filename2 as string 'second File
Dim filename3 as string 'second File
Dim arry () as byte 'is used to read the array of objects.

Filename1 = app. Path + "sige1.ini"
Filename2 = app. Path + "xiaosi. ini"
Filename3 = app. Path + "sige2.ini"

'==================================
'Read the content of sige1.ini and encode it.

Open filename1 for binary as #1
Redim arry (lof (1)-1) 'redefinition Array
Get #1, arry () 'get the content of the first file to the array

For I = 0 to lof (1)-1
Arry (I) = "& H" & hex (arry (I) XOR & h58 '& h58 can certainly be any number
Next I
Close #1

'========================================
'Encoded content (garbled) is written to xiaosi. ini

Open filename2 for binary as #2
Put #2, arry ()
Close #2

'========================================
'Read xiaosi. ini content for decoding

Open filename2 for binary as #3
Redim arry (lof (3)-1)
Get #3, arry ()

For I = 0 to lof (3)-1
Arry (I) = "& H" & hex (arry (I) XOR & h58
Next I
Close #3

'========================================
'Decoded content (garbled) is written to sige2.ini

Open filename3 for binary as #4
Put #4, arry ()
Close #4

Of course, the above is only for file read/write and CODEC operations. As for other requirements of the program itself, you can simply insert this code into the location required by the program.
After writing, let's take a look at the results.

 

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.