ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I need to make a notpad file so it can't be read by a user and only my code. Is that possible? How could it be done?
What's a notepad file? Is it Windows lingo for a text file? If you want a file to be non-readable, but executable, change its permission string to something like --x--x--x, that is,
chmod 0111 filename.txt
If you create the file then the ownership of said file is automatically you. All that needs to be done is to set the permissions. Right click the file, left click properties then select the permissions tab. If you want to make the change via commandline, there's a handy howto here: http://catcode.com/teachmod/
It sounds like you may want only a certain application to be able to read/understand your file, and other tools to be unable. In this case, the file permissions will not help you, since they are not specific to particular applications. Since you have specified that it is a 'notepad' file, I guess you could not use encryption, since that would make it a non-notepad file. The only other recourse may be SELinux, however this is purely speculation, as I know only that I find SELinux too interfering for my use and always disable it on hosts that I install and use. Perhaps someone with SELinux expertise can comment.
--- rod.
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810
Rep:
One simple way would be to encrypt the file before giving it to you Windows user then you may decrypt it when you want to use it.
A notepad file is just an ascii text file so you don't have to worry about special characters/formats.
So say your file is called notepad.txt - on your linux box you could just type :
Code:
cat notepad.txt | rot13 > notepadrot13.txt
Then when you give the file notepadrot13.txt to a Windows user or anyone tries to look at that file ( notepadrot13.txt ) on the Linux machine they'll just see rubbish characters.
To retrieve the file you may type the following to decrypt it:
Code:
cat notepad13.txt | rot13 > notepad.txt
This will put the file back how it was. If you are worried about a linux user accessing the file then the permissions may be set as described or a combination of permissions and encryption used. You will have to rm ( delete )the original file between the encryption and decryption if you don't want an unencrypted version lying around.
If you want only yourself to be able to read the file
chmod u=r,go= filename
Note that if this was produced by MS Notepad program, you should change the line endings to Linux format using dos2unix if this is going to be on Linux.
If you want only 1 prog to be able to read the file, you can either create a dedicated user and use the above chmod, or you'll need to look into encryption...
Certainly you could set up your program to run with the identity of a special user-id (which "exists" but cannot log-on), which owns the files in question. This sort of thing is done, for example, to protect backup-files or print-spool files from unwanted access. The only way that you could get to the file is to log-on as that user ... which you can't do.
The only other alternative is encryption. There are very-robust encryption libraries such as the OpenSSL suite.
Sorry about the confusion i mixed up the words, I did mean .txt file Notepad is windows default I thats my fault I'm meaning to encrypt a text file sorry
Hi,
You can use (at least) libgcrypt and/or gpgme which provide this kind of services for C (and C++) developers. _BUT_ be aware that cryptography is really difficult (it's high end mathematics), and it's easy to misuse these kind of methods, and then introducing a security flaw just by design (as it was proved many time before, remember the dvd css)...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.