1. About.com
  2. Computing & Technology
  3. PHP / MySQL

Discuss in my forum

Crypt () PHP Function

By , About.com Guide

Definition: They Crypt () Function is used for data encryption using an one way algorithm. It is phrased as: string crypt (string input_string , string salt)

Input_string is the string you would like to encrypt, and salt is an optional parameter that influences how the encryption will work. By default PHP uses a two character DES salt string, however if your system standard is MD5, a 12-character salt string is used.

This is most frequently used for handling passwords from the browser to the server.

Also Known As: encrypt, encryption
Examples:
Without salt:

<?php 
 $encrypt = crypt('TextToEncrypt');
 print $encrypt . “ is the encrypted version of TextToEncrypt”;
 ?>

With Salt:

 <?php 
 $encrypt = crypt('TextToEncrypt' , 'd4'); 
 print $encrypt . " is the CRYPT_STD_DES version of TextToEncrypt"; 
 ?> 

For more information please read this article on using the crypt () function.

©2012 About.com. All rights reserved. 

A part of The New York Times Company.