我有一個使用mcrypt
加密的php文件,現在我們需要解密它。使用eval讀取加密文件
這裏是解密:
abstract class Encryption_Abstract {
const CYPHER = 'blowfish';
const MODE = 'cfb';
protected $key;
public
function __construct($key) {
$this->key = $key;
}
public function encrypt($plaintext) {
return $plaintext;
}
public function decrypt($crypttext) {
return $crypttext;
}
}
//decryptor
class Decryption extends Encryption_Abstract {
function decrypt($crypttext) {
$plaintext = '';
$td = mcrypt_module_open(self::CYPHER, '', self::MODE, '');
$ivsize = mcrypt_enc_get_iv_size($td);
$iv = substr($crypttext, 0, $ivsize);
$crypttext = substr($crypttext, $ivsize);
if ($iv) {
mcrypt_generic_init($td, $this - > key, $iv);
$plaintext = mdecrypt_generic($td, $crypttext);
}
return $plaintext;
}
}
現在,這是我們如何實例化,然後使用它:
$enc = new Decryption(KEYS::PROD); //KEYS::PROD is the decryption key
eval($enc->decrypt(file_get_contents("key_file.txt"))); //<--
有什麼辦法來不使用eval
?還是我唯一的選擇?
@Gabi,所以在最後,我將不得不使用'eval()'? – Neal
@你不需要_,但其他解決方案也有類似的安全問題。 –
@Gabi,如果我們加密文件真的不應該是一個問題?我們做這件事的唯一原因就是我們的客戶無法擺弄它 – Neal