Heim  >  Artikel  >  Backend-Entwicklung  >  PHP DES-Verschlüsselungs- und Entschlüsselungsmethodencode

PHP DES-Verschlüsselungs- und Entschlüsselungsmethodencode

little bottle
little bottlenach vorne
2019-04-17 11:50:412228Durchsuche

In diesem Artikel geht es hauptsächlich um den Codeinhalt der DES-Verschlüsselungs- und Entschlüsselungsmethode von PHP. Freunde in Not können sich darauf beziehen.

test.php-Testdatei

<?php
require_once(&#39;Des.php&#39;);

$des = new Des();

$data[&#39;a&#39;] = &#39;a&#39;;
$data[&#39;b&#39;] = &#39;b&#39;;

$conf = [&#39;appkey&#39;=>&#39;AbcdefghijklmnopqrstuvwX&#39;,&#39;secretcode&#39;=>&#39;Abcdefgh&#39;];

$encode = $des->encode($data, $conf);

print_r($encode);
echo "<br>";

$decode = $des->decode($encode,$conf);

print_r($decode);

?>

Des.php

<?php

require_once(&#39;TripleDES.php&#39;);

class Des {

    public static function encode($data, $configKey) {
        $tripleDes = new TripleDES();
        if (is_array($data)) {
            $data = json_encode($data);
        }
        return $tripleDes->encode($data, $configKey["appkey"], $configKey["secretcode"]);
    }

    public static function decode($data, $configKey) {
        $tripleDes = new TripleDES();
        return $tripleDes->decode($data, $configKey["appkey"], $configKey["secretcode"]);
    }

    public static function encodeArr($data, $configKey) {
        $data = json_encode($data);
        return self::encode($data, $configKey);
    }

    public static function decodeArr($data, $configKey) {
        $res = self::decode($data, $configKey);
        return json_decode($res,true);
    }

}

Verwandte Tutorials: PHP-Video-Tutorial

Das obige ist der detaillierte Inhalt vonPHP DES-Verschlüsselungs- und Entschlüsselungsmethodencode. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Stellungnahme:
Dieser Artikel ist reproduziert unter:cnblogs.com. Bei Verstößen wenden Sie sich bitte an admin@php.cn löschen