App接口加密解密方法

//加密
function encrypt($data)
{    
    $key    =   md5("safregr");
    $str = base64_encode($data);
    $res =  base64_encode($str.$key);
    return $res;
}

//解密
function decrypt($data)
{
    $key = md5("safregr");
    $data = base64_decode($data);
    $length = strlen($data);
    $sstr = substr($data,0,-32);
    $bkey = str_replace($sstr,'',$data);   
    if($key != $bkey)
    {
        return false;
    }
    $str = base64_decode($sstr);
    return $str;   
}

 

posted @ 2017-07-25 17:14  郁冬  阅读(3908)  评论(0编辑  收藏  举报