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

Encryptor   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 9
c 1
b 0
f 0
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A decryptData() 0 15 2
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