Update:
Take the following into consideration before using EncFS:
Warning: A security review (February 2014) of encfs discovered a
number of security issues in the stable release 1.7.4 (June 2014).
Please consider the report and the references in it for updated
information before using the release.
It may be prudent to wait for the anticipated EncFS2 stable release.
Original post:
You can do this with EncFS.
On OSX you'll want Mac fusion. This example follows setting one up on dropbox - but it works basically the same for any other use.
For linux:
$ encfs ~/.name ~/name
Note that EncFS comes with some caveats, quote:
... a number of advantages and disadvantages compared to these
systems. Firstly, it does not require any root privileges to
implement; any user can create a repository of encrypted files.
Secondly, one does not need to create a single file and create a
file-system within that; it works on existing file-system without
modifications. This does create a few disadvantages, though; because
the encrypted files are not stored in their own file, someone who
obtains access to the system can still see the underlying directory
structure, the number of files, their sizes and when they were
modified. They cannot see the contents, however. This particular
method of securing data is obviously not perfect, but there are
situations in which it is useful.
This type of system works great for cloud storage sync'ing solutions - but may not fit the needs of your project. In any case, it is an option.