|
@@ -8,7 +8,7 @@
|
|
// +----------------------------------------------------------------------
|
|
// +----------------------------------------------------------------------
|
|
// | Author: 萤火科技 <admin@yiovo.com>
|
|
// | Author: 萤火科技 <admin@yiovo.com>
|
|
// +----------------------------------------------------------------------
|
|
// +----------------------------------------------------------------------
|
|
-declare (strict_types = 1);
|
|
|
|
|
|
+declare (strict_types=1);
|
|
|
|
|
|
// 应用公共函数库文件
|
|
// 应用公共函数库文件
|
|
|
|
|
|
@@ -27,3 +27,24 @@ function getPlatform()
|
|
}
|
|
}
|
|
return $value;
|
|
return $value;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// 加密函数
|
|
|
|
+function encrypt($data, $key = 'vp-256-bit-secret-key')
|
|
|
|
+{
|
|
|
|
+ $method = 'AES-256-CBC';
|
|
|
|
+ $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
|
|
|
|
+ $encrypted = openssl_encrypt($data, $method, $key, 0, $iv);
|
|
|
|
+ // 将iv和加密数据拼接在一起,然后进行base64编码
|
|
|
|
+ return base64_encode($iv . $encrypted);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// 解密函数
|
|
|
|
+function decrypt($data, $key = 'vp-256-bit-secret-key')
|
|
|
|
+{
|
|
|
|
+ $method = 'AES-256-CBC';
|
|
|
|
+ // 解码加密字符串,并分离iv
|
|
|
|
+ $decoded = base64_decode($data);
|
|
|
|
+ $iv = substr($decoded, 0, openssl_cipher_iv_length($method));
|
|
|
|
+ $decrypted = openssl_decrypt(substr($decoded, openssl_cipher_iv_length($method)), $method, $key, 0, $iv);
|
|
|
|
+ return $decrypted;
|
|
|
|
+}
|