Error checking encoded script

I'm trying to do it

<?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.

Note:

  • The key file is created, I already use the fix '\ n'
  • I replaced <?phpand ?>because another question told me that this is a problem
+1
source share
1 answer
<?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 must put the key in

blenckeys

on your server

Note. Sometimes you need to restart apache if you have a "Script Verification" problem

How to use BLENC in PHP?

+1
source

Source: https://habr.com/ru/post/1622813/


All Articles