Is there any way to block access to some particular file or folder in MacOS X, so that it can be protected by password?
Not directly - you have to use an app that accesses the file (e.g. a secure note in 1password or a program like gpg or your own app that encrypts/decrypts a file ) or put the file on an encrypted file system (create using Disk Utility or TrueCrypt etc.) See this question for some ways of encrypting.
Yes and no.
If you want a file to be unreadable by a user without administrator privileges, you can Get Info for that file in the Finder. On the bottom of the information pane, there is a Sharing and Permissions section; setting everyone's settings to "No access" will prevent users of the OS from reading the file under normal circumstances.
anyone with administrator privileges on that system can change the settings back to allowing read access to any user, and
If someone boots from a different boot disk (including the recovery partition in Lion), they can mount the regular filesystem and instruct it to disregard permissions, enabling anyone to read the file.
So it's not super-secure at all, but it is enough to keep nosy regular users without an abundance of technical sophistication out of a file.
Using Terminal you can type the following commands to ensure root only access to the file or folder
chown root /yourfile chmod 700 /yourfile
This ensures that the file is protected by password. (the root password)
You could do the same with any user. In the following command the "example_user" will have read and right access while nobody else will
chown example_user /yourfile chmod 700 /yourfile
You can make the file SIP-protected with
xattr -w com.apple.rootless (file)
That prevents any change until you reverse it with
-d instead of
But it is still readable unless you first use
chmod 000 (file)
Doing it on a directory protects the whole directory.
Another way is to active Apache, put the file in
/Library/Webserver/Documents, make it accessible only to user https, and protect it with .htpasswd