Encryptor   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 28
ccs 9
cts 9
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A decryptData() 0 15 2
1
<?php
2
3
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\MiniProgram;
13
14
use EasyWeChat\Kernel\Encryptor as BaseEncryptor;
15
use EasyWeChat\Kernel\Exceptions\DecryptException;
16
use EasyWeChat\Kernel\Support\AES;
17
18
/**
19
 * Class Encryptor.
20
 *
21
 * @author mingyoung <[email protected]>
22
 */
23
class Encryptor extends BaseEncryptor
24
{
25
    /**
26
     * Decrypt data.
27
     *
28
     * @param string $sessionKey
29
     * @param string $iv
30
     * @param string $encrypted
31
     *
32
     * @return array
33
     *
34
     * @throws \EasyWeChat\Kernel\Exceptions\DecryptException
35
     */
36 2
    public function decryptData(string $sessionKey, string $iv, string $encrypted): array
37
    {
38 2
        $decrypted = AES::decrypt(
39 2
            base64_decode($encrypted, false),
40 2
            base64_decode($sessionKey, false),
41 2
            base64_decode($iv, false)
42
        );
43
44 2
        $decrypted = json_decode($decrypted, true);
45
46 2
        if (!$decrypted) {
47 1
            throw new DecryptException('The given payload is invalid.');
48
        }
49
50 1
        return $decrypted;
51
    }
52
}
53