views:

428

answers:

3

Hi, i've seen many article on encrypt/decrypt of file and typically a button is used to choose the file for encrypt and another button to decrypt the file.

i've seen some application like truecrypt and probably others which does file encryption on-the-fly with transparent. this means that when a encrypted file is clicked to access, it will automatically decrypt and play/open the file. then when the file is closed, it will automatically encrypt again.

some have said that the only way to detect file open is through file system filter.

but is there other ways to do this in c# compact framework?

+1  A: 

You could give all the encrypted files a specific file extension which is handled by your decryption program, then when the user opens the file, your program would decrypt it and then open it in the correct application.

Nate Heinrich
Hi nate, tks for the tip. =)erm i actually tried that but im facing some problems. 1) see here[http://stackoverflow.com/questions/2436295/c-cf-how-to-open-specific-file-extension-with-my-program] 2)another Q i wanna ask is how do i open the file in c# program? i've tried System.Diagnostics.Process proc but it kept returning Win32Exception. 3)when the file is closed, how do i detect and encrypt the file.
A: 

I think I understand your question. You don't control the programs which display the files, you want to just control the encryption anddecryption of the files behind the scenes without the program knowing it even happened (like a .docx file, would be encrypted and decrypted without Word knowing it). I think you should look into WMI. I haven't specifically used it to check for system events having to do with files being retrieved or saved but I have used it to hook into system events and set off code at certain times very effectively. Here is the MSDN reference:

WMI Reference

I would look into the __Instance Events. Like the __InstanceModificationEvent class for file save events to the IO:

__InstanceModificationEvent Reference

Hope this get you onto the right track!

Tim C
Hi Tim, yesh i want to decrypt / encrypt the files behind the scene.however, WMI is not available on windows mobile or CE. =(
A: 

I answered this in the MS Foums. You have to write a file system filter and that filter can only be written in C.

ctacke
Hi chris, to touch with file system filter we will need windows ce embedded correct? and that means visual studio 2005 is needed as well correct?
No, you can write a filter with Visual Studio 2005 or 2008 as a C++ Smart Device project. You don't need Platform Builder (though it will come with a sample, so it's worth downloading the eval edition for the source).
ctacke
is there a sample i can dl online? I tried installing Windows Embedded CE 6.0 and it gave an error. Saying network couldnt be found and eventually it will end with a rollback action.
hmm is okay i managed to get hold of the sample. finally installed platform builder without error
hey chris, sorry but im a little lost here.ok here goes:1. im suppose to create a file system driver and build a fsdspy.dll2. i would then need to upload fsdspy.dll to WM and edit the registry which points to this file.3. after that, how can i use the function in fsdspy.dll from dot net CF?However, i realise that there is already a fsdspy.dll on HKEY_LOCAL_MACHINE\System\StorageManager\Filters\fsdspy. So why do i have to create a new FSD? Can i just use the existing one.
I'm not certain how WinMo mounts the root store any longer, so I honestly don't know if you can filter everything on the device.As far as usage, your driver would have to expose eihter named system events that you catch or use some meachnism for data transport like an IOCTL, point-to-point queue or a memory-mapped file.No idea why the OEM would have included fsdspy - you're going to want to use your own unique name. You can't use the one out of the box becasue you need to add stuff to interact with it.
ctacke
tks chris for the clarification. however, i doubt im able to do a FSD, tts why i came here to look for alternative.I like the idea by Nate Heinrich but im just worried about handling file closed. One solution is to scan the system process table and detect if the file is close and encrypt it.
hi chris, im facing some issues in running the sample fsdspybasically i got the following files: sources, path.cpp, makefile, main.cpp, fsdspy.h, fsdspy.def, find.cpp, file.cppim alittle confused in using windows ce 6.0 so im acutually using borland c++ compiler to try create a dll file.I type this in the command prompt but it gives nothing: make -f sourceswhat am i missing here?
the make file is not designed for Borland's compiler. Eitehr try to build it with Platform Builder (the hard way) or simply create a new Smart Devcei C++ project, add the source files and compile it that way (that's the route I'd take).
ctacke
ok i will try. pardon me if i got more Q =)
hmm im getting errors while i build the solution. i've removed stdafx.h, stdafx.cpp, and the cpp file which came along when i created new c++ smart devices for dll application. for e.g the error im getting are: '#include "fsdspy.h"': skipped when looking for precompiled header use c:\WM_Win32SmartDevice\WM_Win32SmartDevice\file.cpp; Error 2 fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source? c:\WM_Win32SmartDevice\WM_Win32SmartDevice\file.cpp 1279 WM_Win32SmartDevice
turn off precompiled headers
ctacke
thanks chris. tht works but now i get the error Cannot open include file: 'extfile.h': No such file or directory in D:\Program Files\Windows Mobile 6 SDK\PocketPC\include\ARMV4I\fsdmgr.h
erm alright i added extfile.h from D:\Program Files\Windows Mobile 6 SDK\PocketPC\Include\Armv4i and now it works but now im having missing lockmgr.his there some kind of common directory i should add in the sources file?
currently my sources file looks like this:TARGETNAME=fsdspyRELEASETYPE=PLATFORMDLLENTRY=DllMainTARGETTYPE=DYNLINKINCLUDES= \$(_TARGETPLATROOT)\src\incWINCEOEM=1 TARGETLIBS=\ $(_SYSGENSDKROOT)\lib\$(_CPUINDPATH)\coredll.lib \ $(_PROJECTROOT)\cesysgen\oak\lib\$(_CPUINDPATH)\FSDMGR.LIBSOURCES=\ file.cpp \ main.cpp \ path.cpp \ find.cpp
I know where this file is but how do i reference it from the source file? i copied the folder COMMON to D:\Program Files\Windows Mobile 6 SDK\PocketPC\Include and reference this from my source file:$(_TARGETPLATROOT)\src\inc\common\oak\inc; \$(_TARGETPLATROOT)\src\inc\common\sdk\incbut still not getting it
hi chris,i finally managed to create the fsdspy.dll. now i wanna install into the mobile phone. how should i do it??