...

View Full Version : Mcrypt Library explination



ninnypants
10-21-2009, 07:18 PM
Can someone please give me a run down of the Mcrypt Library and it's functions that are used below?

I followed a tutorial on creating a crypter class but the author was very vague if any explanation was give at all about how the Mcrypt Library works, and the reason for the mcrypt functions that were used.



<?php
// Crypter Class

class Crypter{

private $key;
private $algo;

public function __construct($key, $algo = MCRYPT_BLOWFISH){
$this->key = substr($key, 0, mcrypt_get_key_size($algo, MCRYPT_MODE_ECB));
$this->algo = $algo;
}

public function encrypt($data){
$iv_size = mcrypt_get_iv_size($this->algo, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypt = mcrypt_encrypt($this->algo, $this->key, $data, MCRYPT_MODE_ECB, $iv);
return trim(base64_encode($crypt));
}

public function decrypt($data){
$crypt = base64_decode($data);
$iv_size = mcrypt_get_iv_size($this->algo, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypt = mcrypt_decrypt($this->algo, $this->key, $crypt, MCRYPT_MODE_ECB, $iv);
return trim($decrypt);
}
}
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum