Php Blowfish Example - Php

How to do blowfish encryption in php?

Snippet Code


  
Rate this page :
  [ 0 votes]

Blowfish which is a symmetric block cipher used to drop-in replacement for DES or IDEA. It was designed in 1993 by Bruce Schneier to replace the existing encryption algorithms. The sample code which explains the blowfish hashing technique is given below.

<?php $cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, ''); $iv = '12345678'; $key256 = '1234567890123456ABCDEFGHIJKLMNOP'; $key128 = '1234567890123456'; $plaintext = 'Prevention is better than cure'; printf("PlainText: %s\n\n",$plaintext); echo"</br>"; if (mcrypt_generic_init($cipher, $key256, $iv) != -1) { $cipherText = mcrypt_generic($cipher,$plaintext ); mcrypt_generic_deinit($cipher); printf("256-bit blowfish encrypted:n%s\n\n",bin2hex($cipherText)); echo"</br>"; } if (mcrypt_generic_init($cipher, $key128, $iv) != -1) { $cipherText = mcrypt_generic($cipher,$plaintext ); mcrypt_generic_deinit($cipher); printf("128-bit blowfish encrypted:\n%s\n\n",bin2hex($cipherText)); } ?>

Tags


Ask Questions

Ask Question