>  기사  >  백엔드 개발  >  PHP DES 암호화 및 복호화 방법 코드

PHP DES 암호화 및 복호화 방법 코드

little bottle
little bottle앞으로
2019-04-17 11:50:412228검색

이 글은 주로 PHP의 DES 암호화 및 복호화 방법의 코드 내용에 관한 것입니다.

test.php 테스트 파일

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

}

관련 튜토리얼: PHP 비디오 튜토리얼#🎜 🎜#

위 내용은 PHP DES 암호화 및 복호화 방법 코드의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
이 기사는 cnblogs.com에서 복제됩니다. 침해가 있는 경우 admin@php.cn으로 문의하시기 바랍니다. 삭제