PHP Encryptions Tutorial

In this tutorial I’m going to teach you how to use some of the different PHP Encryptions available to us. There are quite a few ways to encrypt or change data using PHP so that the data can be inaccessible or very hard to decipher. I’ll be showing you how to set up a very simple encryption process through a form so that you’ll understand how PHP encryptions work.

The first step is to set up a form that will allow the user to enter some data. So create a new HTML file and within the body we’ll enter:

The <form> creates an action towards “query.php”; this is where we’ll be handling our PHP encryptions. It also uses the method POST, because the information sent to a PHP file using this method becomes invisible through the process so  other users can not see the data. Then we write what we’ll want the user to see, so we write “Enter a string:” followed by an <input type> of text with a name of “addc”. The “addc” name is important to remember because this is what we’ll be using in our PHP file later to access what the user entered.
Then we close everything off with an <input type> of submit, which basically creates an enter button for the user to click and send their information to the PHP file.

So now that the HTML form is complete, we’ll move on to the PHP file that will contain the encryption process for the data.

First create a new PHP file and name is “query.php” PHP scripts are always written between <?php and ?> The first  thing we’ll have to do is access what the user entered, and we’ll do this by writing:

In PHP, variables are written using a dollar sign and a word, so in this case we’ll use $str as our variable. _POST[“addc”] is how we access what the user entered in the form. Before when we created our form we had used the method POST, and this allows us to get any information from the form, so in this case we want what the user actually entered into the text box. We gave the text box a name of “addc”, so $_POST[“addc”] gets whatever is entered in the textbox from the form in the HTML file. Then we enclose this within strip_tags() to strip any HTML or PHP tags the user may have entered. This is usually safe practice for safety and protection from people trying to access hidden information in your forms. Now let’s get on to the different encryptions.

After the user hits submit, and they’re taken to the “query.php” file, we’ll still want them to see what they had entered in their form. So after we declare the variable above, the next thing we’ll write is: (P.S. anything between /* */ is just a comment, so you could keep it in your PHP file if you want as commentary to help you better understand)

 

Some explanations on each of the encryptions:

The MD5 encryption is a widely used cryptographic hash function with a 128-bit hash value. MD5 is also very useful at checking the integrity of files. A few years after the creation of MD5, it was found to be less suitable for several applications and security measures. In recent years, many flaws were found with MD5 dealing with SSL certificates and
checksums of files.

The SHA1 encryption (Secure Hash Algorithm) is a cryptographic hash function designed by the National Security Agency. SHA1 is widely used and employed in several security
applications and protocols.

The uuEncode Algorithm works by converting all the data into a text file with only printable characters. uuEncode was very useful in the earlier days because it addressed the problem of sending binary data file through email.

The ROT13 encryption works by shifting every letter 13 places in the alphabet. It’s a very simple encryption method that only works on letters, numeric and non-alphabetical characters will remain as they are entered.

You can check out an example of PHP encryptions here!

Leave a Reply

Your email address will not be published. Required fields are marked *