Error validation the encoded script

大城市里の小女人 提交于 2019-12-08 04:05:33

问题


I'm trying this

<?php
    /* read the PHP source code */
    $source_code = file_get_contents("hello.php");

    $source_code = preg_replace('#^<\?php\s+#', '', $source_code);
    $source_code = preg_replace('#\s+\?>\s*$#', '', $source_code);

    /* create the encrypted version */
    $redistributable_key = blenc_encrypt($source_code, "encrypt.php", "my_fixed_password");

    $key_file = __DIR__ ."\keys"; 

    file_put_contents($key_file, $redistributable_key . "\n", FILE_APPEND);

    include 'encrypt.php';
    echo $hello;
?>

hello.php

<?php 

$hello = "Ciao";

I got this error

PHP Fatal error:  blenc_compile: Validation of script 
'encrypt.php' failed, cannot execute.

Please note that:

  1. The key file is created, I'm already using the '\n' fix
  2. I replaced <?php and ?> because another Stack Overflow question told me that it's a problem

回答1:


<?php
    $file_name = basename($file);

    $unencrypted_key = = md5(time());

    $source_code = file_get_contents($file);

    //This covers old-asp tags, php short-tags, php echo tags, and normal php tags.
    $contents = preg_replace(array('/^<(\?|\%)\=?(php)?/', '/(\%|\?)>$/'), array('',''), $source_code);

    $html .= "<br> BLENC blowfish unencrypted key: $unencrypted_key" . PHP_EOL;
    $html .= "<br> BLENC file to encode: " . $file_name . PHP_EOL;

    //file_put_contents('blencode-log', "---\nFILE: $file_name\nSIZE: ".strlen($contents)."\nMD5: ".md5($contents)."\n", FILE_APPEND);

    $redistributable_key = blenc_encrypt($contents, TARGET_DIR . '/blenc/' . $file_name, $unencrypted_key);
    $html .= "<br> BLENC size of content: " . strlen($contents) . PHP_EOL;

    /**
    * Server key
    * key_file.blenc
    */
    file_put_contents(TARGET_DIR . '/blenc/' . 'key_file.blenc', $redistributable_key . PHP_EOL);
    $html .= "<br> BLENC redistributable key file key_file.blenc updated." . PHP_EOL;
    exec("cat key_file.blenc >> /usr/local/etc/blenckeys");
?>

https://github.com/codex-corp/ncryptd/blob/master/app/controllers/MagicalController.php#L479

you should put the key to

blenckeys

file on your server

Note: Sometimes you need to reload the apache, if you have "Validation of script" issues

How to use BLENC in PHP?



来源:https://stackoverflow.com/questions/28528797/error-validation-the-encoded-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!