If you want to use bin2hex to โencodeโ binary data so that it can be easily transported via http / url, here is what you can do to undo it back to the binary:
$encoded = bin2hex($some_binary); $decoded = pack('H*', $encoded);
Other minor issues with your class were links to $key and $vector . Since both methods are static, they cannot access $this and $key and $vector only undefined.
The following code should work for you:
class Application_Model_Login { const ENC_KEY = "thisisakeytolock"; const VECTOR = "myvector"; public static function getEnc($input) { $filter = new Zend_Filter_Encrypt(array('adapter' => 'mcrypt', 'key' => self::ENC_KEY)); $filter->setVector(self::VECTOR); $encrypted = $filter->filter($input); return bin2hex($encrypted);
Alternatively, you can use base64_encode in your getEnc function and base64_decode in your getDec function. Base64 is commonly used to represent binary data using encryption.
source share