<?php

/**
 * Classe utilizada para a encriptacao e decriptacao
 * de chaves.
 *
 * @author desenv
 *
 */
class HashAPI {

	var $salt;


	public function HashAPI()
	{
		$this->salt = Configure::read('Hash.salt');
	}

	/**
	 * Método de encriptaçao
	 *
	 * http://php.net/manual/pt_BR/function.mcrypt-encrypt.php
	 * @param unknown_type $text
	 */
	function simple_encrypt($text)
	{
		return trim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $this->salt, $text,
				MCRYPT_MODE_ECB,mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
						MCRYPT_MODE_ECB), MCRYPT_RAND))));
	}

	/**
	 * Método de decriptaçao
	 *
	 * http://php.net/manual/pt_BR/function.mcrypt-decrypt.php
	 * @param unknown_type $text
	 */
	function simple_decrypt($text)
	{
		return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $this->salt, base64_decode($text),
				MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256,
						MCRYPT_MODE_ECB), MCRYPT_RAND)));
	}

}