AesEncryption   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 59
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A encrypt() 0 6 1
A decrypt() 0 6 1
1
<?php
2
3
namespace GusDeCooL\Cryptography\Encryption;
4
5
/**
6
 * Class AesEncryption
7
 *
8
 * @package GusDeCooL\Cryptography\Encryption\AesEncryption
9
 * @author GusDeCooL <[email protected]>
10
 */
11
class AesEncryption
12
{
13
14
    #------------------------------------------------------------------------------------------------------
15
    # Properties
16
    #------------------------------------------------------------------------------------------------------
17
18
    const CHIPPER = 'AES256';
19
    const IV = '\'Nl6P0*3\'Nl6P0*3';
20
21
    /**
22
     * @var string
23
     */
24
    private $secureKey;
25
26
    #------------------------------------------------------------------------------------------------------
27
    # Magic methods
28
    #------------------------------------------------------------------------------------------------------
29
30
    /**
31
     * AesEncryption constructor.
32
     *
33
     * @param string $aesKey security key to use for encryption and decryption
34
     */
35 2
    public function __construct(string $aesKey)
36
    {
37 2
        $this->secureKey = hash('sha256', $aesKey, true);
38 2
    }
39
40
    #------------------------------------------------------------------------------------------------------
41
    # Public methods
42
    #------------------------------------------------------------------------------------------------------
43
44
    /**
45
     * Encrypt the input
46
     *
47
     * @param string $input
48
     * @return string
49
     */
50 1
    public function encrypt(string $input): string
51
    {
52 1
        return base64_encode(
53 1
            openssl_encrypt($input, self::CHIPPER, $this->secureKey, 0, self::IV)
54
        );
55
    }
56
57
    /**
58
     * Decrypt the input
59
     *
60
     * @param string $input
61
     * @return string
62
     */
63 1
    public function decrypt(string $input): string
64
    {
65 1
        return trim(
66 1
            openssl_decrypt(base64_decode($input), self::CHIPPER, $this->secureKey, 0, self::IV)
67
        );
68
    }
69
}
70