Jump to content

PHP Programming/Encryption

From Wikibooks, open books for an open world

PHP provides several functions to encrypt data.

Symmetrical encryption

[edit | edit source]

Storing passwords in clear (unencrypted), in a file or a database, constitutes a security breach. To be able to encrypt and decrypt them, a symmetrical encryption can be done by:

  • openssl_encrypt()[1]
  • openssl_decrypt()

Asymmetrical encryption

[edit | edit source]

The asymmetrical encryption est used to check an identity, via a public and a private key. In PHP, it's done with:

  • openssl_public_encrypt()[2]
  • openssl_private_decrypt()

Hashing

[edit | edit source]

crypt()[3] is a hash function for a string, which can add a salt as an optional second parameter.

References

[edit | edit source]