Friday, March 7, 2014

One way Hash function and Implementation using CodeIgniter in PHP

What is Hash Function?

A cryptographic hash function is a hash function that takes an arbitrary block of data and returns a fixed-size bit string, the cryptographic hash value, such that any change to the data will change the hash value. One way hash function is not decodeable.


Why we will use Hash Function?

The main concerns of computer security are:

  1. data privacy/confidentiality
  2. data integrity
  3. service availability
  4. user authenticity

Different hash functions-
Hash Function
Size(bit)
MD2
64bit
MD5
128bit
SHA1
160 bit
SHA256
256bit
SHA384
384bit
SHA512
512bit

Hash function Implementation using CodeIgniter in PHP-

$this->load->library('encrypt');

$this->encrypt->sha1();

SHA1 encoding function. Provide a string and it will return a 160 bit one way hash. Note: SHA1, just like MD5 is non-decodable.

Example:
$hash = $this->encrypt->sha1('Some string');

Many PHP installations have SHA1 support by default so if all you need is to encode a hash it's simpler to use the native function:

$hash = sha1('Some string');



No comments:

Post a Comment