Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

drewdan's avatar
Level 15

Encrypt Data with PGP

Hey Guys,

I am currently trying to send messages to an Azure Service Bus. I have managed to achieve this using the https://github.com/Azure/azure-sdk-for-php package.

However, I have been asked to encrypt the json messages using PGP. This is something I have never done before and am struggling to find any good guides or packages to handle this.

I understand there is https://www.php.net/manual/en/book.gnupg.php - but I am not sure we have this installed on our server, or if Laravel Vapor even handles this.

If anyone has encountered this issue before and found a way to solve it, I would be most grateful for the assist.

Thanks guys :D

0 likes
3 replies
bugsysha's avatar
bugsysha
Best Answer
Level 61

Not sure if something like this can help https://github.com/spatie/crypto

But as I remember there was nothing complex there. What is confusing you?

$gnupg = new gnupg();
$gnupg->import('public.asc');
$gnupg->addencryptkey('fingerprint');
$encrypted = $gnupg->encrypt('json');
1 like
drewdan's avatar
Level 15

Thanks for the response, going to pull down that Spatie package shortly once I have some test coverage over what I have that works currently and see if it does what I think its going to do.

This stuff has always confused me, think I am about to get my head around it though.

I believe my initial confusion is around what types of encryption there are and how they work. As part of my instructions for this, I was guided to use a PGP-Key and told to download some software called Gpg4win. Which generates a key pair. So then my thought was, well what is different to this and say a key I can generate with the PuTTY key generator, are they the same? And then my head explodes with the worry I will not be able to get this done.

And then do I encrypt with the private key, and then the public key is used to decrypt, or is it the other way around.

From my brief glance, I guess the spatie package will allow me to generate the key value pairs inside my laravel application, rather than using an external application like PuTTY? And then it can use them to encrypt and decrypt?

I think I am beginning to understand it. Sorry I am reading this back and this post sounds more like a brain dump of me trying to understand what this stuff does, rather than a proper response!

bugsysha's avatar

OK, then I'll leave you to figure it out so I don't disrupt your concentration. Don't worry. You will make it.

Please or to participate in this conversation.