Skip to content
Advertisement

How do I encrypt a file with gnupg and php? [closed]

I am not a PGP expert and php isn’t my first language, so I am having some trouble using gnupg to encrypt a file. I can get it to encrypt strings just fine.

If I use PGPTool (windows) to encrypt my file and then open it in a text editor it looks like binary data…

JavaScript

If I read in the file and encrypt it with gnupg i get a plain text result, as if it were to be pasted into an email.

JavaScript

My problem is, I need it to be output as the first option for sending to a specific client. Is there a way to get gnupg and php to do this?

Advertisement

Answer

Refering to the PHP-manpages (https://www.php.net/manual/en/function.gnupg-setarmor.php) the default output is a text file with base64 encoded data:

JavaScript

Using the gnupg-setarmor function you can set the output to a binary output:

JavaScript

Here is the complete code:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement