How to use *.pub/*.sec files to encrypt/decrypt another file?

I created a pair of *.pub and *.sec files using the instructions and code given here:

https://www.gnupg.org/documentation/manuals/gnupg/Unattended-GPG-key-generation.html

(I am using this documentation because the ultimate application I have in mind is an automated encryption/decryption pipeline.)

Q1: How can I use gpg2 and the *.pub file to encrypt another file?

Q2: How can I use gpg2 and the companion *.sec to decrypt a file encrypted using the companion *.pub file?

Important: I am interested only in answers that are suitable for programmatic/unsupervised implementation. Please do not post answers that can only be carried out interactively.


Any pointers to relevant documentation would be greatly appreciated. I’ve never been so disoriented when learning about a piece of software as I am with gpg2.