Preventing other application from opening custom file vb.net - vb.net

I have a text file. Now I have changed its file type from .txt to .abc. My VB.NET program loads the text into textboxes from that file. After changing the file type, however, other apps like NotePad and Word are able to open and read my .abc file.
Is there any way that only my application will be able to open/read from the file and no other app would be able to do so? What I mean is, suppose I have a PhotoShop document .psd file, no other app, rather that photoshop itself, can open it. How do I make my file unreadable by other apps?

There is no way to prevent an app that you don't develop from opening any file. The extensions are just there for helping us humans, and maybe a bit for the computer to know the default app you select for an extension.
Like you said, a .txt file can be opened by many many apps. You can open a .txt file with Notepad, Firefox, VSCode, and many others.
Same way, a .psd file can be opened by many many apps. You can open that .psd file with Photoshop, but also Notepad, Firefox, and VSCode, and probably the same apps as above.
The difference is which apps can read and understand the file.
In order to make a file not understandable by other apps, you need to make it into a format that cannot recognize, because you planned it "in secret".
Like Visual Vincent said above, you could encrypt the file in a way, or you can have a binary file, that basically only your app knows know to understand.
Since you dont own the app you want the file to be understood by, then you either have to accept that it can be opened by any app that can open files, or you can try to encrypt the file outside the app, or like zipping it with a password, and then decrypting or unzipping when you want to use it.

Firstly, any file can be read unless it is still open by a particular process or service. Even PhotoShop files can be 'read' by NotePad - try it!
So, an attempt at my first answer...
You can try a couple of methods to prevent opening the file, for instance, applying a file lock. As an example, SQL Server .mdf files are locked by the SQL Server service. This happens because the files are maintained in an open state, however; your application would have to remain running to keep these files open. Technically, though, the files can still be copied.
Another way is to set the hidden attribute for the file. This hides the file from the less savvy users, but it will be displayed if the user show's hidden files.
And my second answer: You refer to the format of files by saying only PhotoShop can read or write its own files (not true, but I know what you're saying).
The format of the file must be decided by yourself. You must determine how you are going to store the data that you output from your application. It looks like you have been attempting to write your application data into a text file. Perhaps you should try writing to binary files instead. Binary files, while not encrypted, as suggested by Visual Vincent in the comments to your question, still provide a more tailored approach to storing your data.
Binary files write raw binary data instead of humanised text. For instance, if you write an integer to the file it will appear as a string of four bytes, not your usual 123456789 textual format.
So, you really need to clarify what data you want to write to the file, decide on a set structure to your file (as you also have to be able to read it back in to your application) and then be able to write the information.

Related

custom file open with custom application only

I am working on vb.net application where I wanted to create and read a file. File will have specific extension for ex. .abcb the way I want my application to work is:
can create a file with .abcd extension
should read .abcd files only(and also application created files only so altered extension shouldn't be working)
.abcd files should show some garbage data when open in any other application(ex. word, notepad any image viewer etc.)
Now my application does 1,2(partly) step, i.e. it creates a file and load data also, it reads .abcd files only(not the altered files)
but created file can be read by other software's also.I tried searching a lot but have not found anything and don't know where to start.
Any help is appreciated!
if you don't want other programs to be able to read the content of your file then your going to have to mask it in some way, which is usually done with encryption.
assuming your not too worried about the key being compromised, the easiest way to accomplish this would be to generate a key with something like System.Security.Cryptography and use that key to encyrpt everything you send to the file and everything you read from it.
as for making your own file extension, you can make the extension of a file whatever you want when you make it:
Dim fs As FileStream = File.Create("/path/to/file/filename" & ".abcd")
the only thing that the extension does is tell the OS what progam to use when opening a file by default, which will probably be notepad since your making your own extension

vb.net using a custom file to save different types of data

I'm brushing up on my VB.NET skills for a future project I will be working on. This application will be very data intensive, requiring 20+ data tables, user supplied images, and possibly even short audio/video files.
I want to be able to save all of this information into a single, external file, so that the user can share what they create with the world.
Ideally, I would like all the text based data to be stored in a database format that I can easily work with, preferably via the entity framework.
Pretty much all the information I'm finding relates to only saving a single text/XML file, and that will not really work for me. Can anyone point me in the proper direction, or suggest a method that will let me save the data?
I'm working inside Visual Studio 2012 Pro, with a Visual Basic Windows Form Application. Please let me know if you need any additional information.
I'll expand my comment to an answer instead.
As previously mentioned this sounds like a zip file. In this you can:
Have a file called databasetables.txt or whatever containing the database tables.
You can have Audio, Video, Images etc in respective folders. This way when you open your file you can just load all files in the Audio folder to get the expected files.
You can have information stored in xmlfiles.
Endless posibilities...
Just keep in mind that you might want to load all this only into the memory of the computer so you dont extract it onto the hard drive.
And you dont have to save the file as .zip to open it as .zip, just select your own cool suffix which will look neat :)

How to create advance PDF file encryption and protection using php?

I have a problem about PDF file encryption using php.
Case: Let's say I have a local system (web based) to upload and download files, such as 4sh*red (dot) com, but it just allows PDF file. A user sign up and login to download the PDF files using his or her own personal computer. After users downloaded a PDF file from my system, the file can be viewed only on computer where they downloaded the file. But, if another user copy it (I mean: downloaded PDF file) to another computer, the file can't be viewed on that computer.
Note: I don't mean here about protecting the PDF files using password because nowadays there are a lot of softwares used to remove PDF's password protection. But, the file can't be viewed at all if copied to another computer.
Can we do that in php? If yes, do you know any algorithm to solve the case?
I really appreciate your response or answers.
Thank you.
The PDF format is an open format by Adobe. This means there are a lot of programs out there that can read it and quite same that can modify it.
If you write your own program and add some stuff to the PDF, then maybe you can do this.
Another question is - why don't you just make the document visible in the web browser to the user? Of course there's still going to be a way around for savvy users to get it, but most noobs wouldn't know how and you can easily close the simplest blocks (like right click / save).
What maybe interesting to do is what a lot of companies are doing with videos nowadays: you can dynamically add some hidden or visible 'info' to a PDF that identifies who you sent it to. In that way, if the PDF shows up somewhere else - you know who spread it.... Again - PDF is an open format, so anyone can always erase whatever you write in the main contents, so you'd have to add a hidden image to the content or something.

Recommended document structure. File Wrappers? Roll my own?

I'm currently working out the best structure for a document I'm trying to create. The document is basically a core data document that uses sqlite as its store, but uses the Apple provided NSPersistentDocument+FileWrapperSupport to enable file wrapper support.
The document makes heavy use of media, such as images, videos, audio files, etc. with potentially 1000s of files. So what I'm trying to do is create a structure similar to the following:
/myfile.ext/
/myfile.ext/store.sqlite
/myfile.ext/content/
/myfile.ext/content/images/*
/myfile.ext/content/videos/*
/myfile.ext/content/audio/*
Now, first of all I went down the route of creating a temporary directory and placing all of my media in there. Basically creating the paths and file names '/content/images/image1.jpg' as I wanted them to appear in the saved file wrapper, and then upon save I attempted to copy these all into the filewrapper...
What I found was that the files were indeed copied into the wrapper with the file structure I wanted, but when the actual wrapper was saved, these files all magically disappeared.
Great.
So, I trashed my existing solution and tried to use file wrappers instead. This solution involved creating a content wrapper file directory when a new document was created, or loading in a content directory file wrapper upon opening a document.
When an image was added/modified, I created the necessary directory wrappers inside this root content wrapper (i.e. an images directory wrapper if it didn't already exist, or any other intermediary directory wrappers that needed to be created) and then created a regular file wrapper for the media, removing any existing wrapper for that file name if one was there.
Saving the document was just a case of making sure the content file wrapper was added to the document file wrapper, and the document would save.
Well... it did. The first time. However, any attempts to make any subsequent changes i.e add an image, save. Then replace image, save. Did not behave as expected, only showing the image from the first save.
So, my question is... first of all, which of the above approaches is the correct one, if at all, and what am I doing that wrong for them to fail.
And secondly, as I expect to be managing 1000s of images, is using file wrappers the correct way to go about things at all.
With that much media in play, you should likely give your users control over whether the media resides in the document or only a reference to the media is included in the document, and the media resides elsewhere, such as in a library/repository managed by your application. Then they could save out a (potentially many times larger) copy with all references resolved.
You might want to zip/unzip any directory so that users don't get confused trying to attach the document to an email. I believe iWork has been doing this with its document bundles for a while now.
As far as what you are doing wrong, no-one can say, as you haven't provided any code demonstrating what you are doing.
Why don't you create a one-off application that lets you select files on disk and saves those files in a document using a file wrapper? This would let you tackle this functionality without any interference from other issues in your application. Once you understand how to use file wrappers, you can port the code back or just write new code that works.

How are files validated when opened?

Suppose a user selects a file in a dialogue box, and the app then opens the file for reading, etc. Users can open "incorrect" files--they can select a binary file, for example, even if the file they're supposed to be selecting is a text file.
I recognize that sometimes improper file types generate exceptions, which can be handled. But sometimes the files don't create exceptions; instead, they just cause the application to work improperly.
What's the standard way to code for these kinds of situations?
Put a unique identifier into the file (usually the first line or some tag)
Restrict the file extension
Do a check on the file whether it's OK
Use 1. if possible or use both 2. and 3.
A lot of operating systems help you out with this by providing filesystem APIs that are at least somewhat file-type-aware (in Cocoa for Mac OS X, there's a setAllowedFileTypes: method on NSOpenPanel, for example). Aside from that, you should make sure to define your file format in a way that's easy for you to identify when your program opens a file. A few well-known bytes at the start of your file is probably enough to protect you from most random-file problems.