I want to have a program like this:
scanf("%s", name);
scanf("%s", id);
scanf("%d", &age);
Now I want to write name
, id
and age
to a file, but the file should be encrypted, so that only my program can read back the data it wrote.
Do I need to use one of the encryption libraries mentioned here (they all are pretty heavy duty libraries, I just need to encrypt a text file), or is there any other simpler method?
If an encryption library is the solution, which one is best suited for a simple text file encryption?
Windows Encrypting File SystemTo use EFS to encrypt your file, right-click the text file and select Properties. Now, select Advanced, then check the box to Encrypt contents to secure data. Press OK, then Apply.
The encrypt() function uses an array of 16 48-bit keys produced by the setkey() function to encode bytes specified by the block argument according to the Data Encryption Standard (DES) encryption algorithm or to decode argument bytes according to the DES decryption algorithm.
Using a plug-in for the popular Windows text editor, Notepad++, you can easily encrypt selected text and entire text files.
If you want security, it is a mistake to roll your own encryption library. Use a well established encryption library (even if it may seem bloated), and leave security and its proper implementation to the experts.
If you can use C++, I suggest Crypto++, and if you can't use C++, then I suggest you implement a C wrapper library around Crypto++. Another possibility is libcrypto, although it lacks support for AES.
I should warn you, though, that if the program and the text file are on the same machine, you will need to have the password supplied externally (e.g. by the user); passwords that are embedded in programs are easily extracted, and offer no security at all. If the program is inaccessible (e.g. it is located on a webserver, and someone with the text file won't have access to the executable), then it is ok.
Better use a symmetric-key algorithm, as AES. You can find small sourcecodes here for instance.
If your applications are critical, then you should use the libraries you linked to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With