Created
December 26, 2011 16:57
-
-
Save galvao/1521642 to your computer and use it in GitHub Desktop.
Usando mcrypt com Zend Framework via helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[production] | |
; Configuração normal do ZF | |
my.crypto.IV = "nononononononononononono" | |
my.crypto.Key = "nononononononononononononononono" | |
; A cifra e o modo devem ser CONSTANTES e não strings. | |
my.crypto.Cipher = MCRYPT_RIJNDAEL_192 | |
my.crypto.Mode = MCRYPT_MODE_CFB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Helper_Decrypt extends Zend_Controller_Action_Helper_Abstract | |
{ | |
private $applicationConfig, $cryptoConfig, $result; | |
public function direct($cryptedData, $base64Decode = TRUE) | |
{ | |
$this->applicationConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); | |
$this->cryptoConfig = $this->applicationConfig->my->crypto; | |
if ($base64Decode) { | |
$cryptedData = base64_decode($cryptedData); | |
} | |
$this->result = mcrypt_decrypt($this->cryptoConfig->Cipher, $this->cryptoConfig->Key, $cryptedData, $this->cryptoConfig->Mode, $this->cryptoConfig->IV); | |
return $this->result; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Helper_Encrypt extends Zend_Controller_Action_Helper_Abstract | |
{ | |
private $applicationConfig, $cryptoConfig, $result; | |
public function direct($rawData, $base64Encode = TRUE) | |
{ | |
$this->applicationConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); | |
$this->cryptoConfig = $this->applicationConfig->my->crypto; | |
$this->result = mcrypt_encrypt($this->cryptoConfig->Cipher, $this->cryptoConfig->Key, $rawData, $this->cryptoConfig->Mode, $this->cryptoConfig->IV); | |
if ($base64Encode) { | |
return base64_encode($this->result); | |
} else { | |
return $this->result; | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment