This is a continuation of a previous question ( GnuPG: How to encrypt/decrypt files using a certain key? ), I need to:
This may seem like a complicated way to decrypt data, suffice to say that I have strong reasons to do that. I may be wrong but I can't just decrypt files by supplying the private key via the commandline (this would be perfect but it seems I can't do that), ie.
exec("gpg --use-key=private-key.gpg -o $clear_file_name --decrypt $encr_file_name");
So, how can I dynamically load/use private PGP key, use it to decrypt data, then unload it from keyring
OR (if this is not possible), are there any other similar tool that allows me to achieve this?
PS. The code will be run on a linux EC2 instance
You need to use gpg's --homedir
option, i.e. with a temporary dir that you can delete afterwards. See this answer at superuser for an example.