瀏覽代碼

访问日志

541469799@qq.com 1 年之前
父節點
當前提交
14fbbe4286
共有 1 個文件被更改,包括 17 次插入2 次删除
  1. 17 2
      app/index/common.php

+ 17 - 2
app/index/common.php

@@ -29,7 +29,7 @@ function getPlatform()
 }
 
 // 加密函数
-function encrypt(string $data, $key = 'vp-256-bit-secret-key')
+function encrypt0(string $data, $key = 'vp-256-bit-secret-key')
 {
     $method = 'AES-256-CBC';
     //$iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($method));
@@ -40,8 +40,15 @@ function encrypt(string $data, $key = 'vp-256-bit-secret-key')
     return base64_encode($iv . $encrypted);
 }
 
+function encrypt(string $data)
+{
+    $timestamp = time();
+    $pre0 = str_repeat('0', 10 - strlen($data));
+    return strrev(strval($timestamp)) . $pre0 . $data;
+}
+
 // 解密函数
-function decrypt($data, $key = 'vp-256-bit-secret-key')
+function decrypt0($data, $key = 'vp-256-bit-secret-key')
 {
     $method = 'AES-256-CBC';
     // 解码加密字符串,并分离iv
@@ -50,3 +57,11 @@ function decrypt($data, $key = 'vp-256-bit-secret-key')
     $decrypted = openssl_decrypt(substr($decoded, openssl_cipher_iv_length($method)), $method, $key, 0, $iv);
     return $decrypted;
 }
+
+function decrypt($data)
+{
+    if (empty($data) || strlen($data) < 10){
+        return 0;
+    }
+    return intval(substr($data, 10));
+}