国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Heim 類庫下載 PHP類庫 PHP implementiert die Bildverschlüsselung und -entschlüsselung und unterstützt Salting

PHP implementiert die Bildverschlüsselung und -entschlüsselung und unterstützt Salting

Oct 10, 2016 am 11:08 AM

一個簡單的圖片加解密函數(shù)

使用client跑,不要使用瀏覽器跑

PHP implementiert die Bildverschlüsselung und -entschlüsselung und unterstützt Salting

PHP implementiert die Bildverschlüsselung und -entschlüsselung und unterstützt Salting

PHP implementiert die Bildverschlüsselung und -entschlüsselung und unterstützt Salting

<?php
/**
 * Created by hello.
 * User: qq 845875470
 * Date: 2016/4/2
 * Time: 11:21
 */

$notice = <<<A
    為了穩(wěn)定性,必須在客戶端跑
    格式 :php path=D:/xxx/uuu type=en is_copy=1 salt=xxx
    參數(shù)使用空格分開
    path        -- 路徑 必須寫
    type        -- en加密, de為解密 必須寫
    is_copy        -- 1為復制,0為轉(zhuǎn)移,                 不寫默認為轉(zhuǎn)移
    salt        -- 加密鑰匙 加密用什么,解密就用什么    不寫默認為salt
A;

//如果不是客戶端
if(PHP_SAPI != &#39;cli&#39;) {echo $notice;die;}

//獲取參數(shù)
$arr = parse_parameter($argv);

//如果路徑?jīng)]設置
if(!isset($arr[&#39;path&#39;]) || !isset($arr[&#39;type&#39;]))     {echo $notice;die;}
//如果is_dir沒設置
if(!isset($arr[&#39;is_copy&#39;]))                         {$arr[&#39;is_copy&#39;] = &#39;&#39;;}
//如果salt沒設置
if(!isset($arr[&#39;salt&#39;]))                             {$arr[&#39;salt&#39;] = &#39;&#39;;}

//type為en就加密
if($arr[&#39;type&#39;] == "en") img_enconde($arr[&#39;path&#39;], $arr[&#39;is_copy&#39;], $arr[&#39;salt&#39;]);
//type為de就解密
if($arr[&#39;type&#39;] == "de") img_deconde($arr[&#39;path&#39;], $arr[&#39;is_copy&#39;], $arr[&#39;salt&#39;]);


function parse_parameter($argv)
{
    $arr = array();
    //獲取參數(shù)
    for($len=count($argv)-1; $len--; )
    {
        list($key, $val) = explode(&#39;=&#39;, $argv[$len]);
        $arr[$key] = $val;
    }
    return $arr;
}


//圖片加密函數(shù)
//路徑文件夾
//是否為復制(默認不復制)
//鹽(默認為salt)
function img_enconde($path, $is_copy = 0, $salt = &#39;salt&#39;)
{
    $time1 = microtime(1);
    $handle = opendir($path);
    if(!$salt) $salt = &#39;salt&#39;;
    if($handle)
    {
        echo "路徑:" . $path . "\r\n\r\n";
        //在指定文件夾下創(chuàng)建臨時文件夾
        $temp_dir = $path . &#39;\\&#39; . &#39;temp&#39;;
        @mkdir($temp_dir, 0777, 1);

        while ($file = readdir($handle))
        {
            $time2 = microtime(1);
            //構造當前文件絕對地址
            $dir_path = $path . &#39;\\&#39; . $file;
            //獲取文件后綴
            $suffix = strrchr($file, &#39;.&#39;);
            //圖片后綴
            $fix = array(&#39;.jpg&#39;, &#39;.gif&#39;, &#39;.bmp&#39;, &#39;.png&#39;, &#39;.jpeg&#39;, &#39;.JPG&#39;, &#39;.GIF&#39;, &#39;.BMP&#39;, &#39;.PNG&#39;, &#39;JPEG&#39;);

            if(is_file($dir_path) && in_array($suffix, $fix))
            {
                //打開當前文件
                $fh = fopen($dir_path, &#39;r&#39;);

                //打開文件為流
                $stream = fread($fh, filesize($dir_path));
                //輸出
                file_put_contents($temp_dir . &#39;\\&#39; . uniqid(&#39;&#39;,1), $file . &#39;!&#39; . $salt . &#39;@&#39; . $stream);
                //關閉句柄
                fclose($fh);

                //是否為復制
                //1為復制,0為刪除(默認)
                if(!$is_copy)
                {
                    echo "加密并刪除 : " . $dir_path . "\r\n";
                    @unlink($dir_path);
                }
                else
                {
                    echo "加密 : " . $dir_path . "\r\n";
                }
                $time3 = microtime(1);
                echo "此圖用時 ", ($time3 - $time2), " S\r\n", "已經(jīng)用時 ", ($time3 - $time1), " S\r\n\r\n";
            }
        }

        echo "加密完成\r\n";
    }
    else
    {
        echo "path invalid ";
        return false;
    }
}

//圖片解密函數(shù)
//路徑文件夾
//是否為復制(默認不復制)
//鹽(默認為salt)加密寫什么,這里就寫什么
function img_deconde($path, $is_copy = 0, $salt = &#39;&#39;)
{
    $time1 = microtime(1);
    $handle = opendir($path);
    if($handle)
    {
        echo "路徑:" . $path . "\r\n\r\n";
        if(!$salt) $salt = &#39;salt&#39;;

        //在指定文件夾下創(chuàng)建臨時文件夾
        $temp_dir = $path . &#39;\\&#39; . &#39;temp&#39;;
        @mkdir($temp_dir, 0777, 1);

        //核心正則
        $reg = "#^(.+?[jpgifbmne]{3,4})!(" . $salt . ")@#im";
        $res = array();

        $count = 0;
        while ($file = readdir($handle))
        {
            $time2 = microtime(1);
            //構造當前文件絕對地址
            $file_path = $path . &#39;\\&#39; . $file;

            if(is_file($file_path))
            {
                //文件句柄
                $hf = fopen($file_path, &#39;r&#39;);
                //返回流
                $stream = fread($hf, filesize($file_path));
                fclose($hf);

                //匹配加的密碼
                if(preg_match_all($reg, $stream, $res))
                {
                    $count++;
                    //清空鹽
                    $stream = str_replace($res[0][0], &#39;&#39;, $stream);
                    //輸出文件
                    file_put_contents($temp_dir . &#39;\\&#39; . $res[1][0], $stream);

                    //是否為復制
                    //1為復制,0為刪除(默認)
                    if(!$is_copy)
                    {
                        echo "成功解密刪除 : " . $temp_dir . &#39;\\&#39; . $res[1][0] . "\r\n";
                        @unlink($file_path);
                    }
                    else
                    {
                        echo "解密 : " . $temp_dir . &#39;\\&#39; . $res[1][0] . "\r\n";
                    }
                }
                $time3 = microtime(1);
                echo "此圖用時 ", ($time3 - $time2), " S\r\n", "已經(jīng)用時 ", ($time3 - $time1), " S\r\n\r\n";
            }
        }
        if(!$count)
        {
            echo "沒有有效的加密文件\r\n";
            return false;
        }
        echo "解密完成\r\n";
    }
    else
    {
        echo "path invalid ";
        return false;
    }
}

?>


Erkl?rung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Hei?e KI -Werkzeuge

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Clothoff.io

Clothoff.io

KI-Kleiderentferner

Video Face Swap

Video Face Swap

Tauschen Sie Gesichter in jedem Video mühelos mit unserem v?llig kostenlosen KI-Gesichtstausch-Tool aus!

Hei?e Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)

Hei?e Themen

PHP-Tutorial
1502
276