Setting file permissions programmatically?

I’d like to build a portal page that will lets users (web site users, not system users) view files that pertain to them. For example, if I uploaded a PDF of a contract for them to view and download.

How can I handle setting the permissions for that programmatically?