Sign in Join
Wiki copytemporary

CryptINI: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-## Contents
2-
3- * 1 CryptINI
4- * 1.1 Screenshots
5- * 1.2 Purpose
6- * 1.3 Disclaimer
7- * 1.4 Encryption
8- * 1.5 FPC versions
9- * 1.6 Use and Example Code
10- * 1.6.1 Simple use
11- * 1.6.2 Using the WriteIdent etc in Form.Create
12- * 1.7 Encrypting/Decrypting the whole INI file
13- * 1.8 Original IniFiles methods and properties
14- * 1.9 Testing App/Demo
15- * 1.10 Documentation
16- * 1.11 Licence
17- * 2 Download
18- * 2.1 Package Installation
19-
201## CryptINI
212
223### Screenshots
234
24-
25-
26- * Screenshot of Test/Demo app
27-
28-[![latest testcryptini.jpg](/wiki-images/b/b9/latest_testcryptini.jpg)](</File:latest_testcryptini.jpg>)
29-
30- * Contents of INI written by CryptINI
31-
32-[![testcryptini1.jpg](/wiki-images/e/e5/testcryptini1.jpg)](</File:testcryptini1.jpg>)
5+* Screenshot of Test/Demo app ![](/wiki-images/5/5d/Latest_testcryptini.jpg)\
6+* Contents of INI written by CryptINI ![](/wiki-images/c/cb/Testcryptini1.jpg)
337
348### Purpose
359
36-TCryptIni is a TiniFile implementation that is resistant to tampering. In normal (PlainTextMode = FALSE) mode, any calls to Write values are accompanied by an embedded MD5 hash value (and also reversed then Base64/IDEA Encrypted) This is invisible in normal use (i.e. read methods return normal results) but there are added methods to internally verify any entries. It also is able to write a standard ident section containing various details including authorship and copyright. A single function allows you to check on app startup whether this section has been altered. It also includes a useful 'First Run' functionality. It's intended purpose is to store information that cannot be easily altered in a text editor (such as HiScores etc) by a weekend scripter. The WriteInteger method is the most secure as it double-encrypts as well as embedding an MD5Hash value as a checksum. Very handy to save scores etc. It is paired with ReadInteger and VerifyInteger
10+TCryptIni is a TiniFile implementation that is resistant to tampering. In normal (PlainTextMode = FALSE) mode, any calls to Write values are accompanied by an embedded MD5 hash value (and also reversed then Base64/IDEA Encrypted) This is invisible in normal use (i.e. read methods return normal results) but there are added methods to internally verify any entries. It also is able to write a standard ident section containing various details including authorship and copyright. A single function allows you to check on app startup whether this section has been altered. It also includes a useful 'First Run' functionality. It's intended purpose is to store information that cannot be easily altered in a text editor (such as HiScores etc) by a weekend scripter. The WriteInteger method is the most secure as it double-encrypts as well as embedding an MD5Hash value as a checksum. Very handy to save scores etc. It is paired with ReadInteger and VerifyInteger
3711
3812### Disclaimer
3913
40-This unit does not claim to pass any security tests nor be used in any environment where a moderate-level hacker could circumvent it.
14+This unit does not claim to pass any security tests nor be used in any environment where a moderate-level hacker could circumvent it.
4115
4216### Encryption
4317
44-By Default CryptINI uses the DCPCrypt package for string encryption. The mode is IDEA cipher with an MD5 hash for the key. The EncryptINI and DecryptINI methods use DCPCrypt RC4 Cipher (With SHA hash) There is a $DEFINE USE_DCPCRYPT directive at the top of the ucryptini file.
18+By Default CryptINI uses the DCPCrypt package for string encryption. The mode is IDEA cipher with an MD5 hash for the key. The EncryptINI and DecryptINI methods use DCPCrypt RC4 Cipher (With SHA hash) There is a \$DEFINE USE_DCPCRYPT directive at the top of the ucryptini file.
4519
46-If this DEFINE is commented out, then CryptINI will default to BASE64 string encryption, which is weaker. Encrypt/DecryptINI methods will be unavailable. You can then delete any requirement for dcpcrypt in the project inspector.
20+If this DEFINE is commented out, then CryptINI will default to BASE64 string encryption, which is weaker. Encrypt/DecryptINI methods will be unavailable. You can then delete any requirement for dcpcrypt in the project inspector.
4721
4822### FPC versions
4923
50-Starting in FPC V3.1.1 there are additional options in TINIFile which are implemented in TCryptINI if the FPC Version >= 3.1.1 is detected.
24+Starting in FPC V3.1.1 there are additional options in TINIFile which are implemented in TCryptINI if the FPC Version \>= 3.1.1 is detected.
5125
5226### Use and Example Code
5327
54- * **Tip:** Add CryptINI as a requirement in Project Inspector
28+- **Tip:** Add CryptINI as a requirement in Project Inspector
5529
5630#### Simple use
5731
58-Instead of
59-```
32+Instead of
33+
34+``` pascal
6035Uses Inifiles;
61- TForm1.SomeProcedure;
62- Var INI:TIniFile;
63- begin
64- INI := TIniFile.Create(ChangeFileExt(Application.EXEName, '.cfg'));
65- end;
36+TForm1.SomeProcedure;
37+Var INI:TIniFile;
38+begin
39+ INI := TIniFile.Create(ChangeFileExt(Application.EXEName, '.cfg'));
40+end;
6641```
6742
68-You do: (note the 'uses ucryptini')
69-```
43+You do: (note the 'uses ucryptini')
44+
45+``` pascal
7046Uses ucryptini;
71- TForm1.SomeProcedure;
72- Var INI:TCryptIniFile;
73- begin
74- INI := TCryptIniFile.Create(ChangeFileExt(Application.EXEName, '.cfg'));
75- end;
47+TForm1.SomeProcedure;
48+Var INI:TCryptIniFile;
49+begin
50+ INI := TCryptIniFile.Create(ChangeFileExt(Application.EXEName, '.cfg'));
51+end;
7652```
7753
78- * If you do:
54+- If you do:
7955
80-```
56+``` pascal
8157INI.PlainTextMode=True;
82- INI.SectionHashing:=False;
58+INI.SectionHashing:=False;
8359```
8460
85-.. then TCryptINI will behave *exactly* as TIniFile does, so you can drop it into existing code without changing an existing INI file.
61+.. then TCryptINI will behave *exactly* as TIniFile does, so you can drop it into existing code without changing an existing INI file.
8662
87- * If you are coding a new app, then leave PlainTextmode as its default value (TRUE) and code as you would for Tinifile. The advantage is that you can then use CryptINI's extra methods, like Verify and WriteIdent etc.
63+- If you are coding a new app, then leave PlainTextmode as its default value (TRUE) and code as you would for Tinifile. The advantage is that you can then use CryptINI's extra methods, like Verify and WriteIdent etc.
8864
8965#### Using the WriteIdent etc in Form.Create
9066
91- * You can hard-code an Ident Section in your INI file and check if it has been altered
92- * **Note** to use this function you must include Version Info in your project (Project/Project Options/Version Info)
93- * Typical Form.Create()
67+- You can hard-code an Ident Section in your INI file and check if it has been altered
68+- **Note** to use this function you must include Version Info in your project (Project/Project Options/Version Info)
69+- Typical Form.Create()
9470
95-```
71+``` pascal
9672procedure TForm1.FormCreate(Sender: TObject);
97- const
98- C_KEYPHRASE = 'I do like to be beside the seaside'; // Move this to the top of the unit
99- Begin
100- ...other code
101- // Initialise the encrypted config file
102- INI := TCryptIniFile.Create(ChangeFileExt(Application.EXEName, '.cfg'));
103-
104- // First ever run. INI is absent
105- If INI.IsVirgin then INI.WriteIdent('minesadorada','(c)2016','minesadorada@charcodelvalle.com','Creative Commons',TRUE);
106-
107- if NOT INI.VerifyIdent('5b319674f5cb55f3ed1e404e33c25868') then // I got this from the INI file
108- ShowMessage('This is not a genuine copy of ' + Application.Title + '!')
109- else INI.Deflower; // If not Deflowered then the default ini is used.
110-
111- // After first run, use the encrypted version
112- If NOT INI.IsVirgin then
113- begin
114- INI.DecryptINI(TRUE,C_KEYPHRASE);
115- // Check the unencrypted version..
116- if NOT INI.VerifyIdent('5b319674f5cb55f3ed1e404e33c25868') then // I got this from the INI file
117- ShowMessage('This is not a genuine copy of ' + Application.Title + '!');
118- end;
119- INI.KeyPhrase:=C_KEYPHRASE; // for subsequent read/writes
120- ...other code
121- end;
122-
123- procedure Tmainform.FormDestroy(Sender: TObject);
124- const
125- C_KEYPHRASE = 'I do like to be beside the seaside'; // Move this to the top of the unit
126- Begin
127- ...other code
128- INI.EncryptINI(TRUE,C_KEYPHRASE);
129- ...other code
130- end;
131-```
73+const
74+ C_KEYPHRASE = 'I do like to be beside the seaside'; // Move this to the top of the unit
75+Begin
76+ ...other code
77+ // Initialise the encrypted config file
78+ INI := TCryptIniFile.Create(ChangeFileExt(Application.EXEName, '.cfg'));
13279
133- * Has the Ident been tampered with? Put something like this in Form.Create:
80+ // First ever run. INI is absent
81+ If INI.IsVirgin then INI.WriteIdent('minesadorada','(c)2016','minesadorada@charcodelvalle.com','Creative Commons',TRUE);
13482
83+ if NOT INI.VerifyIdent('5b319674f5cb55f3ed1e404e33c25868') then // I got this from the INI file
84+ ShowMessage('This is not a genuine copy of ' + Application.Title + '!')
85+ else INI.Deflower; // If not Deflowered then the default ini is used.
86+
87+ // After first run, use the encrypted version
88+ If NOT INI.IsVirgin then
89+ begin
90+ INI.DecryptINI(TRUE,C_KEYPHRASE);
91+ // Check the unencrypted version..
92+ if NOT INI.VerifyIdent('5b319674f5cb55f3ed1e404e33c25868') then // I got this from the INI file
93+ ShowMessage('This is not a genuine copy of ' + Application.Title + '!');
94+ end;
95+ INI.KeyPhrase:=C_KEYPHRASE; // for subsequent read/writes
96+ ...other code
97+end;
98+
99+procedure Tmainform.FormDestroy(Sender: TObject);
100+const
101+ C_KEYPHRASE = 'I do like to be beside the seaside'; // Move this to the top of the unit
102+Begin
103+ ...other code
104+ INI.EncryptINI(TRUE,C_KEYPHRASE);
105+ ...other code
106+end;
135107```
108+
109+- Has the Ident been tampered with? Put something like this in Form.Create:
110+
111+``` pascal
136112// Use the MD5 value from the INI file (use your own!)
137- If INI.VerifyIdent('92abf0deecbb25c435bff507a396d92a') then
138- ShowMessage('Ident verified OK') // do nothing
139- else
140- ShowMessage('Ident failed verification'); // Warning message/exit
113+If INI.VerifyIdent('92abf0deecbb25c435bff507a396d92a') then
114+ ShowMessage('Ident verified OK') // do nothing
115+else
116+ ShowMessage('Ident failed verification'); // Warning message/exit
141117```
142118
143- * Test for first run
119+- Test for first run
144120
145-```
121+``` pascal
146122If INI.IsVirgin then // note that doing the test Deflowers the app by default
147- ShowMessage('First time run of this app');
123+ ShowMessage('First time run of this app');
148124```
149125
150- * Toggle to normal UnEncrypted INI use
126+- Toggle to normal UnEncrypted INI use
151127
152-(by default it is set to FALSE)
153-```
128+(by default it is set to FALSE)
129+
130+``` pascal
154131INI.PlainTextMode:=TRUE;
155- INI.WriteString('MySection', 'String', 'MyString'); // just writes normally
132+INI.WriteString('MySection', 'String', 'MyString'); // just writes normally
156133```
157134
158- * When PlainTextMode = FALSE (default) and SectionHashing=TRUE (default),Write<anytype> encrypts the value and prefixes the encrypted value with an MD5Hash. In addition each section has an entry MD5Hash=<32 characters> which is updated on each write.
135+- When PlainTextMode = FALSE (default) and SectionHashing=TRUE (default),Write\<anytype\> encrypts the value and prefixes the encrypted value with an MD5Hash. In addition each section has an entry MD5Hash=\<32 characters\> which is updated on each write.
159136
160-```
137+``` pascal
161138INI.WriteInteger('MySection', 'Integer',1000);
162139```
163140
164- * Note WriteInteger adds a '+' (INTEGER_MARKER) to the written Key
141+- Note WriteInteger adds a '+' (INTEGER_MARKER) to the written Key
165142
166-This is so that CryptINI can deal with Integers specially Using CryptINI in either mode, this is invisible in use (i.e. don't add a + to the ident for any methods)
143+This is so that CryptINI can deal with Integers specially Using CryptINI in either mode, this is invisible in use (i.e. don't add a + to the ident for any methods)
167144
168- * When PlainTextMode = FALSE (default), use these convenient methods if you like:
145+- When PlainTextMode = FALSE (default), use these convenient methods if you like:
169146
170-```
147+``` pascal
171148INI.ReadUnencryptedString
172- INI.WriteUnencryptedString
173- INI.ReadUnEncryptedInteger
174- INI.WriteUnencryptedInteger
149+INI.WriteUnencryptedString
150+INI.ReadUnEncryptedInteger
151+INI.WriteUnencryptedInteger
175152```
176153
177- * Store 'First Run' status using these methods:
154+- Store 'First Run' status using these methods:
178155
179-```
156+``` pascal
180157INI.IsVirgin
181- INI.Deflower
182- INI.ReFlower (useful for testing)
158+INI.Deflower
159+INI.ReFlower (useful for testing)
183160```
184161
185162### Encrypting/Decrypting the whole INI file
186163
187- * You can encrypt and decrypt the entire INI file using methods EncryptINI and DecryptINI.
164+- You can encrypt and decrypt the entire INI file using methods EncryptINI and DecryptINI.
188165
189-This uses a different cipher and hash method, so is extra-secure.
166+This uses a different cipher and hash method, so is extra-secure.
190167
191- * Note: CryptINI methods and properties an only work with an unencrypted INI file, So; Decrypt on startup, and Encrypt before exit.
192- * By default the routines use the KeyPhrase property, but you can override this in the EncryptINI/DecryptINI method calls along with whether to delete the "old" file and what file extension to use for the encrypted file.
168+- Note: CryptINI methods and properties an only work with an unencrypted INI file, So; Decrypt on startup, and Encrypt before exit.
169+- By default the routines use the KeyPhrase property, but you can override this in the EncryptINI/DecryptINI method calls along with whether to delete the "old" file and what file extension to use for the encrypted file.
193170
194171### Original IniFiles methods and properties
195172
196-Just use them as normal. Note: you can mix-and-match Plaintext and Encrypted in the same INI file. Just toggle the property PlainTextMode before Writing/Reading
173+Just use them as normal. Note: you can mix-and-match Plaintext and Encrypted in the same INI file. Just toggle the property PlainTextMode before Writing/Reading
197174
198175### Testing App/Demo
199176
200- * This can be downloaded from <https://sourceforge.net/projects/lazautoupdate/files/otherpackages/testcryptini_compiled.zip>
201- * There are compiled versions for Windows 32/64-bit and Linux 32/64-bit in the archive. (Also untested MacOS 10 'Darwin' 32-bit)
177+- This can be downloaded from <https://sourceforge.net/projects/lazautoupdate/files/otherpackages/testcryptini_compiled.zip>
178+- There are compiled versions for Windows 32/64-bit and Linux 32/64-bit in the archive. (Also untested MacOS 10 'Darwin' 32-bit)
202179
203180### Documentation
204181
205- * As well as this page, ucryptini.pas is heavily commented. The Testing app (source also commented) will help you understand the strengths and limitations of CryptINI, and how to get the best of it in your own applications.
182+- As well as this page, ucryptini.pas is heavily commented. The Testing app (source also commented) will help you understand the strengths and limitations of CryptINI, and how to get the best of it in your own applications.
206183
207184### Licence
208185
209- * [ModifiedGPL](<https://www.gnu.org/licenses/gpl-faq.en.html>)
186+- [ModifiedGPL](https://www.gnu.org/licenses/gpl-faq.en.html)
210187
211188## Download
212189
213- * Sourcecode and Testing app Direct link: <https://sourceforge.net/projects/lazautoupdate/files/otherpackages/cryptinitest_source.zip>
214- * CryptIni as a component: via [[Online Package Manager]]
190+- Sourcecode and Testing app Direct link: <https://sourceforge.net/projects/lazautoupdate/files/otherpackages/cryptinitest_source.zip>
191+- CryptIni as a component: via [[Online Package Manager]]
215192
216193### Package Installation
217194
218- * Download the package: <https://sourceforge.net/projects/lazautoupdate/files/otherpackages/cryptini.zip>
219- * Unzip it into a new folder (Suggest <LazarusDir>/components/cryptini)
220- * In the Lazarus IDE Click Package/Open Package File (lpk), navigate to your new folder and click "cryptini.lpk", then "Open"
221- * Just click "Compile". It is not a visual component, so cannot be "Installed"
222- * To use it in your project, just add ucryptini to the Uses clause when required, or better still: add CryptIni (the component) to the projects's requirements.
223-
224-
195+- Download the package: <https://sourceforge.net/projects/lazautoupdate/files/otherpackages/cryptini.zip>
196+- Unzip it into a new folder (Suggest \<LazarusDir\>/components/cryptini)
197+- In the Lazarus IDE Click Package/Open Package File (lpk), navigate to your new folder and click "cryptini.lpk", then "Open"
198+- Just click "Compile". It is not a visual component, so cannot be "Installed"
199+- To use it in your project, just add ucryptini to the Uses clause when required, or better still: add CryptIni (the component) to the projects's requirements.
225200
226-* * *
201+----
227202
228-[Minesadorada](</User:Minesadorada> "User:Minesadorada")
203+Minesadorada
229204
230205---
231-*From the Free Pascal wiki, page "CryptINI", as the Internet Archive kept it on 2025-04-17. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
206+*From the Free Pascal wiki, page "CryptINI", as it stood on 2019-08-30 after a change by Minesadorada, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
207+Category: Components

Back to history