Skip to content

Commit 60d8548

Browse files
committed
modify func
1 parent c8930e6 commit 60d8548

File tree

1 file changed

+11
-41
lines changed

1 file changed

+11
-41
lines changed

Authcode.php

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,33 @@
11
<?php
22

3-
namespace Authcode;
3+
namespace Wilon\Encryption;
44

55
class Authcode
66
{
7-
/**
8-
* The authcode key.
9-
*
10-
* @var string
11-
*/
12-
protected $key;
13-
14-
/**
15-
* Create a new authcode instance.
16-
*
17-
* @param string $key
18-
* @return void
19-
*
20-
* @throws \RuntimeException
21-
*/
22-
public function __construct($key)
23-
{
24-
$this->key = $key;
25-
}
267

278
/**
289
* Encode the given value.
2910
*
3011
* @param string $value
31-
* @param bool $serialize
12+
* @param string $key
13+
* @param integer $expiry
3214
* @return string
33-
*
34-
* @throws \Illuminate\Contracts\Encryption\EncryptException
3515
*/
36-
public function encode($value, $expiry = 0)
16+
public static function encode($value, $key, $expiry = 0)
3717
{
38-
$this->authcode($value, 'ENCODE', $this->key, $expiry);
18+
return static::authcode($value, 'ENCODE', $key, $expiry);
3919
}
4020

4121
/**
4222
* Decode the given value.
4323
*
44-
* @param string $value
45-
* @param bool $serialize
24+
* @param string $value
25+
* @param string $key
4626
* @return string
47-
*
4827
*/
49-
public function decode($value, $expiry = 0)
28+
public static function decode($value, $key)
5029
{
51-
$this->authcode($value, 'DECODE', $this->key, $expiry);
30+
return static::authcode($value, 'DECODE', $key);
5231
}
5332

5433
/**
@@ -60,12 +39,12 @@ public function decode($value, $expiry = 0)
6039
* @param integer $expiry
6140
* @return string
6241
*/
63-
protected function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
42+
protected static function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0)
6443
{
6544

6645
$ckey_length = 4;
6746

68-
$key = md5($key ? $key : UC_KEY);
47+
$key = md5($key ? $key : AUTHCODE_KEY);
6948
$keya = md5(substr($key, 0, 16));
7049
$keyb = md5(substr($key, 16, 16));
7150
$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
@@ -111,13 +90,4 @@ protected function authcode($string, $operation = 'DECODE', $key = '', $expiry =
11190
}
11291
}
11392

114-
/**
115-
* Get the authcode key.
116-
*
117-
* @return string
118-
*/
119-
public function getKey()
120-
{
121-
return $this->key;
122-
}
12393
}

0 commit comments

Comments
 (0)