Passed
Push — master ( 67c0a2...6d4ce9 )
by ma
02:20
created

Encryptor::decryptData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 15
rs 10
cc 2
nc 2
nop 3
1
<?php
2
/**
3
 * Encryptor
4
 */
5
namespace tinymeng\OAuth2\Helper;
6
7
class Encryptor{
8
9
    /**
10
     * 解密数据(微信小程序手机号登)
11
     * @param string $sessionKey
12
     * @param string $iv
13
     * @param string $encrypted
14
     * @return array
15
     * @throws \Exception
16
     */
17
    public function decryptData(string $sessionKey, string $iv, string $encrypted): array
18
    {
19
        $decrypted = AES::decrypt(
20
            base64_decode($encrypted, false),
21
            base64_decode($sessionKey, false),
22
            base64_decode($iv, false)
23
        );
24
25
        $decrypted = json_decode($decrypted, true);
26
27
        if (!$decrypted) {
28
            throw new \Exception("The given payload is invalid.");
29
        }
30
31
        return $decrypted;
32
    }
33
}
34