Encrypt and Decrypt Secret Documents with PHP

Maybe you would like to encrypt some of your documents to avoid the content of them could be shared with unwanted users.

In this story, I will show you a simple solution based on PHP 5/7/8 that lets you encrypt and decrypt strings, protect them with a password and securely share them with other users.

To do it we have to build an encrypt function such as:

This code will generate an encrypted string:
sh4XQQ1FWJiarQo4qp97OqOOF4sqA00VqBYjDWP+XbE=

This string contains the original data: Secret Data Here!

And it’s protected by a secret key (password): Secret_123

You can share it with another user or conserve it, the code to decrypt it is:

--

--

I’m a Software Developer based in Milan. I use Laravel to create awesome Web Applications and I’m an Open Source enthusiast and supporter.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrea Pollastri

I’m a Software Developer based in Milan. I use Laravel to create awesome Web Applications and I’m an Open Source enthusiast and supporter.