Passed
Push — master ( 2340f1...c1e1ba )
by Breno
03:15 queued 01:20
created

OpenCrypt   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
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 37
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A encrypt() 0 10 1
A decrypt() 0 9 1
1
<?php
2
3
namespace OpenCrypt;
4
5
class OpenCrypt
6
{
7
    private $encryptMethod = "AES-256-CBC";
8
    private $secretKey;
9
    private $secretIV;
10
11 1
    public function __construct(
12
        string $secretKey,
13
        string $secretIV
14
    ) {
15
        // hash
16 1
        $this->secretKey = hash('sha256', $secretKey);
17
        // iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
18 1
        $this->secretIV = substr(hash('sha256', $secretIV), 0, 16);
19 1
    }
20
21 1
    function encrypt($value) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
22 1
        $output = openssl_encrypt(
23 1
            $value,
24 1
            $this->encryptMethod,
25 1
            $this->secretKey,
26 1
            0,
27 1
            $this->secretIV
28
        );
29 1
        return base64_encode($output);
30
    }
31
32 1
    function decrypt($value) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
33 1
        return openssl_decrypt(
34 1
            base64_decode($value),
35 1
            $this->encryptMethod,
36 1
            $this->secretKey,
37 1
            0,
38 1
            $this->secretIV
39
        );
40
    }
41
}
42