Encryption Techniques for Your PHP Development [con't]
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 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:
- I send him a bag with an open padlock.
- He puts the message in the bag and locks it with the padlock that I sent him.
- He sends the locked bag containing the message back to me.
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