Is it possible to unlock a directory/folder containing sensitive data at the beginning of an operation then lock it again when finished using it?
Yes, this is quite straightforward to achieve on Linux by using standard filesystem permissions to “lock” a folder. Typically, a normal directory is set to permissions like 755, which you can verify using:
stat -c "%a %n" /path/to/folder/to/lock
And to prevent any access:
chmod 000 /path/to/folder/to/lock
The attached ZIP includes a unit that implements this concept. It can lock and unlock a folder using a password, and the included screenshots demonstrate the expected behaviour. It also applies a simple XOR-based obfuscation/encryption method.
While testing, I ran into a rather amusing issue: I locked the test folder while the lock-state file was still inside it, which effectively prevented any way of unlocking it through normal means. That was an interesting lesson learned. Of course, I later confirmed that root can still bypass the protection and unlock the folder. (Davo and his bright ideas made me do this ::))
So, this should be treated strictly as a proof of concept. It demonstrates the idea, but it is not suitable for production use unless you are the sole user with full control of the system.
Have fun experimenting, and let me know if it works on Windows as well. The code is designed to be cross-platform, although I have not yet tested it there.
Instructions to Use :
The app launches with a default password already set. You are welcome to change it — or live dangerously and keep it.
Click the Lock button. A folder selection dialog will appear. Choose the folder you wish to lock, click OK, and let the magic happen.
Try accessing the folder you just locked. The system will politely respond with something like: “uh-uh… no can do, sorry.” 🚫
To reverse the damage (or responsibility), click the Unlock button and repeat the same selection process. Everything should return to normal… theoretically.
Warning: If you forget the password or decide to improvise halfway through, you are officially on your own. No refunds, no undo button, and definitely no sympathy from the filesystem. If this happens root is your friend!