john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

encrypt decrypt

<?php

// sudo apt-get install php5-mcrypt

$key = 'password to (en/de)crypt';
$string = 'some content here';

//http://php.net/manual/en/function.mcrypt-encrypt.php , no IV in this example but IV's, PBKDF2 etc. are all recommended best practice

$encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key))));
$decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0");

var_dump($encrypted);
var_dump($decrypted);

  • « command convert audio avconv
  • Linux pxe boot systemrescuecd fdisk gparted usb creator parted »

Published

Nov 14, 2013

Category

php

~43 words

Tags

  • decrypt 2
  • encrypt 4
  • php 82