PHP DES encryption and decryption method code

little bottle
Release: 2023-04-05 21:50:01
forward
2320 people have browsed it

This article is mainly about the code content of PHP's DES encryption and decryption method. Friends in need can refer to it.

test.php test file

<?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);

?>
Copy after login

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);
    }

}
Copy after login

Related tutorials: PHP video tutorial

The above is the detailed content of PHP DES encryption and decryption method code. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template