1 | <?php |
||
16 | class Signature |
||
17 | { |
||
18 | /** |
||
19 | * Khóa bí mật dùng để tạo và kiểm tra chữ ký dữ liệu. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $hashSecret; |
||
24 | |||
25 | /** |
||
26 | * Loại thuật toán mã hóa sẽ sử dụng. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $hashType; |
||
31 | |||
32 | /** |
||
33 | * Khởi tạo đối tượng DataSignature. |
||
34 | * |
||
35 | * @param string $hashSecret |
||
36 | * @param string $hashType |
||
37 | * @throws InvalidArgumentException |
||
38 | */ |
||
39 | public function __construct(string $hashSecret, string $hashType = 'sha256') |
||
48 | |||
49 | /** |
||
50 | * Trả về chữ ký dữ liệu của dữ liệu truyền vào. |
||
51 | * |
||
52 | * @param array $data |
||
53 | * @return string |
||
54 | */ |
||
55 | public function generate(array $data): string |
||
62 | |||
63 | /** |
||
64 | * Kiểm tra tính hợp lệ của chữ ký dữ liệu so với dữ liệu truyền vào. |
||
65 | * |
||
66 | * @param array $data |
||
67 | * @param string $expect |
||
68 | * @return bool |
||
69 | */ |
||
70 | public function validate(array $data, string $expect): bool |
||
76 | |||
77 | /** |
||
78 | * Phương thức cho biết loại mã hóa truyền vào có được VNPay hổ trợ hay không. |
||
79 | * |
||
80 | * @param string $type |
||
81 | * @return bool |
||
82 | */ |
||
83 | protected function isSupportHashType(string $type): bool |
||
87 | } |
||
88 |