当前位置 : 主页 > 网络编程 > PHP >

CryptOpensslAes.php

来源:互联网 收集:自由互联 发布时间:2021-06-28
CryptOpensslAes.php class CryptOpensslAes{ const AES_METHOD = 'AES-128-ECB'; private $secretKey = ''; private $signKey = ''; public function __construct($secretKey,$signKey){ $this-secretKey = $secretKey; $this-signKey = $signKey; } /** * 解
CryptOpensslAes.php
class CryptOpensslAes
{
    const AES_METHOD = 'AES-128-ECB';

    private $secretKey = '';

    private $signKey = '';

    public function __construct($secretKey,$signKey){
        $this->secretKey = $secretKey;
        $this->signKey = $signKey;
    }

    /**
     * 解密
     * @param $secretData
     * @return string
     */
    public function decode($secretData){
        return openssl_decrypt($secretData, self::AES_METHOD, $this->secretKey, false);
    }

    /**
     * 加密
     * @param $data
     * @return string
     */
    public function encode($data){
        return openssl_encrypt($data, self::AES_METHOD, $this->secretKey, false);
    }

    /**
     * 签名
     * @param $data
     * @return string
     */
    public function sign($data){
        return md5($data.$this->signKey);
    }

    /**
     * 检测签名
     * @param $data
     * @param $sign
     * @return bool
     */
    public function checkSign($data,$sign){
        return $this->sign($data) == $sign;
    }
}
上一篇:for.php
下一篇:db.txt
网友评论