LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2008, 11:34 AM   #1
Jayfrin
LQ Newbie
 
Registered: Apr 2008
Posts: 19

Rep: Reputation: 0
Making Notepad files unreadable


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?
 
Old 09-11-2008, 11:59 AM   #2
Uncle_Theodore
Member
 
Registered: Dec 2007
Location: Charleston WV, USA
Distribution: Slackware 12.2, Arch Linux Amd64
Posts: 896

Rep: Reputation: 71
Quote:
Originally Posted by Jayfrin View Post
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
 
Old 09-11-2008, 12:00 PM   #3
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 6, KDE Neon
Posts: 4,313

Rep: Reputation: 212Reputation: 212Reputation: 212
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/
 
Old 09-11-2008, 01:59 PM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.
 
Old 09-11-2008, 02:37 PM   #5
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
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.
 
Old 09-11-2008, 08:24 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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...

Last edited by chrism01; 09-15-2008 at 01:34 AM.
 
Old 09-11-2008, 09:35 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
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.
 
Old 09-13-2008, 04:08 AM   #8
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Ubuntu, Debian, OS X
Posts: 1,305

Rep: Reputation: 107Reputation: 107
Download "ccrypt-1.7-1" rpm. Its easy to use.
 
Old 09-14-2008, 09:50 PM   #9
Jayfrin
LQ Newbie
 
Registered: Apr 2008
Posts: 19

Original Poster
Rep: Reputation: 0
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
 
Old 09-15-2008, 04:23 AM   #10
ErV
Senior Member
 
Registered: Mar 2007
Location: Russia
Distribution: Slackware 12.2
Posts: 1,202
Blog Entries: 3

Rep: Reputation: 62
Quote:
Originally Posted by vikas027 View Post
Download "ccrypt-1.7-1" rpm. Its easy to use.
"Gnu Pretty Good Privacy" (GnuPG, gpg) is better.
 
Old 09-16-2008, 07:48 AM   #11
Jayfrin
LQ Newbie
 
Registered: Apr 2008
Posts: 19

Original Poster
Rep: Reputation: 0
Is there a way I could do stuff like this through a line of C++ code.
 
Old 09-16-2008, 08:08 AM   #12
jf.argentino
Member
 
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
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)...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
music icons change to documents and files become unreadable, help :( dateofexpiration Ubuntu 4 02-06-2008 05:15 AM
text files that dont open with notepad the_imax General 6 02-16-2005 05:52 AM
making .tif files into animated .gif files (bash shell, Red Hat 7.2) illiniguy3043 Linux - Newbie 1 06-01-2004 04:04 PM
Notepad in linux wh33t Linux - Software 10 05-24-2004 10:10 PM
notepad in java, help Lord-AG Programming 7 05-12-2004 06:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration