Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p><strong>Historical Note:</strong> This was written at the time of PHP4. This is what we call "legacy code" now.</p> </blockquote> <p>I have left this answer for historical purposes - but some of the methods are now deprecated, DES encryption method is not a recommended practice, etc.</p> <p>I have not updated this code for two reasons: 1) I no longer work with encryption methods by hand in PHP, and 2) this code still serves the purpose it was intended for: to demonstrate the minimum, simplistic concept of how encryption can work in PHP. </p> <p>If you find a similarly simplistic, "PHP encryption for dummies" kind of source that can get people started in 10-20 lines of code or less, let me know in comments.</p> <p>Beyond that, please enjoy this Classic Episode of early-era PHP4 minimalistic encryption answer.</p> <hr> <p>Ideally you have - or can get - access to the mcrypt PHP library, as its certainly popular and very useful a variety of tasks. Here's a run down of the different kinds of encryption and some example code: <a href="http://www.osix.net/modules/article/?id=606" rel="nofollow">Encryption Techniques in PHP</a></p> <pre><code>//Listing 3: Encrypting Data Using the mcrypt_ecb Function &lt;?php echo("&lt;h3&gt; Symmetric Encryption &lt;/h3&gt;"); $key_value = "KEYVALUE"; $plain_text = "PLAINTEXT"; $encrypted_text = mcrypt_ecb(MCRYPT_DES, $key_value, $plain_text, MCRYPT_ENCRYPT); echo ("&lt;p&gt;&lt;b&gt; Text after encryption : &lt;/b&gt;"); echo ( $encrypted_text ); $decrypted_text = mcrypt_ecb(MCRYPT_DES, $key_value, $encrypted_text, MCRYPT_DECRYPT); echo ("&lt;p&gt;&lt;b&gt; Text after decryption : &lt;/b&gt;"); echo ( $decrypted_text ); ?&gt; </code></pre> <p>A few warnings:</p> <p>1) Never use reversible, or "symmetric" encryption when a one-way hash will do.</p> <p>2) If the data is truly sensitive, like credit card or social security numbers, stop; you need more than any simple chunk of code will provide, but rather you need a crypto library designed for this purpose and a significant amount of time to research the methods necessary. Further, the software crypto is probably &lt;10% of security of sensitive data. It's like rewiring a nuclear power station - accept that the task is dangerous and difficult and beyond your knowledge if that's the case. The financial penalties can be immense, so better to use a service and ship responsibility to them.</p> <p>3) Any sort of easily implementable encryption, as listed here, can reasonably protect mildly important information that you want to keep from prying eyes or limit exposure in the case of accidental/intentional leak. But seeing as how the key is stored in plain text on the web server, if they can get the data they can get the decryption key.</p> <p>Be that as it may, have fun :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload