How to use BLENC in PHP?

I have a testcode.php file need to encode:

<?php
    $hello = "Hello World!";
?>

And I created file encode.php to encrypt and test that file:

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

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

    /* read which is the key_file */
    $key_file = ini_get('blenc.key_file');

    /* save the redistributable key */
    file_put_contents($key_file, $redistributable_key, FILE_APPEND);

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

but I recevied these errors when I ran encode.php:

Warning: blenc_compile: Validation of script 'encrypt.php' failed. MD5_FILE: 910e6a45f806ba3dc42830839971cb53 MD5_CALC: c38a6b2f389267a272ea656073a463ed in C:xampphtdocsPHPEncodeencode.php on line 14

and

Fatal error: blenc_compile: Validation of script 'encrypt.php' failed, cannot execute. in C:xampphtdocsPHPEncodeencode.php on line 14

Help me fix it, thank you! :)


BLENC has issues when there is more than one redistributable key in blenc.key_file. See PHP bug #68490 that I've reported.

Also when you run your script multiple times, redistributable keys will get corrupted in blenc.key_file. This is because you are appending to the file, but all keys are saved on the same line (the same broken example is on php manual page). You should change it to:

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

The second Fatal error you got was probably because of corrupted blenc.key_file.


;) just delete " <?php ?> " in your page *.php compiled this not with " <?php and ?> "

just $hello = "Hello World!";

and is ok :) !


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

    $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_namenSIZE: ".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

链接地址: http://www.djcxy.com/p/20948.html

上一篇: Chrome和IE返回不同的SHA哈希值

下一篇: 如何在PHP中使用BLENC?