1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- <?php namespace App\Servers\Encrypts;
- /**
- * 自定义简单对称加密
- *
- * @author 刘相欣
- */
- class Simple
- {
- /**
- * 简单对称加密算法之加密
- *
- * @param String $contents 需要加密的内容
- *
- * @return String
- *
- * */
- public function encode($contents)
- {
- //先用base64编码
- $contents = base64_encode($contents);
- //替换掉符号
- $encrypted = str_replace(['=', '+', '/'], [md5('ZZ22'), md5('Z22Z'), md5('XGHJ')], $contents);
- //返回结果
- return $encrypted;
- }
- /**
- * 简单对称加密算法之解密
- *
- * @param String $encrypted 需要解密的内容
- *
- * @return String
- *
- * */
- public function decode($encrypted)
- {
- //替换掉符号
- $encrypted = str_replace([md5('ZZ22'), md5('Z22Z'), md5('XGHJ')], ['=', '+', '/'], $encrypted);
- //先用base64编码
- $decrypted = base64_decode($encrypted);
- //返回结果
- return $decrypted;
- }
- }
|