Encryption Techniques for Your PHP Development | 2 | WebReference

Encryption Techniques for Your PHP Development | 2


Encryption Techniques for Your PHP Development [con't]

Symmetric Encryption

Symmetric encryption involves encrypting a string using a key. So both the sender and receiver must have the key to perform both the encrypting and decrypting. This type of encryption has an obvious flaw: anyone who gets the key will be able to view your secret message. The difficulty is making sure that sender and receiver are the only people who know the key. Here is an example of this kind of encryption in PHP:

Check your version of PHP to verify the latest encryption methods that will work with the above encryption functions. When I run the above code, I get the following result:

Asymmetric Encryption

Asymmetric encryption is very common these days. The system is used a lot on the Internet, most commonly through Secure Socket Layer (SSL), for which PHP provides support. This type of encryption is a bit difficult to explain, so bear with me while I do the best I can. Suppose someone wants to send me a secret message. If our exchange were to follow asymmetric encryption, it would happen like this:

  1. I send him a bag with an open padlock.
  2. He puts the message in the bag and locks it with the padlock that I sent him.
  3. He sends the locked bag containing the message back to me.

Because I am the only person with the key to the padlock, I am the only person in the world who can unlock it and access the message. That is more or less how asymmetric encryption works.

In my next couple of articles, I will explain how to create a secure online diary that uses encryption and decryption.

Original: May 5, 2010