我有以下课程:
<?php
class Application_Model_Classes_Cryptography
{
private static $key = "thisisakeytolock";
private static $vector= "myvector";
public static function encrypt($data)
{
$filter = new Zend_Filter_Encrypt(array('adapter' => 'mcrypt', 'key' => Application_Model_Classes_Cryptography::$key));
$filter->setVector(Application_Model_Classes_Cryptography::$vector);
$encrypted = $filter->filter($data);
return utf8_encode(base64_encode($encrypted));
}
public static function decrypt($data)
{
$filter = new Zend_Filter_Decrypt(array('adapter' => 'mcrypt', 'key' => Application_Model_Classes_Cryptography::$key));
$filter->setVector(Application_Model_Classes_Cryptography::$vector);
$decrypted = $filter->filter(base64_decode(utf8_decode($data)));
return $decrypted;
}
}
但是当我使用这些方法时,结果似乎是正确但不起作用
$varData = 'someinformation';
$conData = Application_Model_Classes_Cryptography::decrypt(Application_Model_Classes_Cryptography::encrypt($varData));
echo $varData;
echo $conData;
if($varData == $conData) echo "equal";
else echo "not equal";
结果如下:
someinformation
someinformation
not equal
任何人都可以帮助我理解这里的错误。
基本上我想发送一些加密信息,一旦在其他服务器接收就想要解密并提取该信息。但问题是信息似乎是相同的,但没有比较。我已经尝试在方法中添加utf8_encode和解码,但是没有收获。
系统详细信息:
操作系统:Mac OS X 10.11
MAMP: 3.5
PHP: 5.6.10