Completed
Push — master ( d044a7...7ba68a )
by Florent
03:57
created

OpenSSLEncryptor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A encrypt() 0 4 1
A decrypt() 0 4 1
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace AESKW;
13
14
final class OpenSSLEncryptor implements EncryptorInterface
15
{
16
    private $kek;
17
    private $method;
18
19
    public function __construct($kek)
20
    {
21
        $this->kek = $kek;
22
        $this->method = 'aes-'.(strlen($kek)*8).'-ecb';
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function encrypt($data)
29
    {
30
        return openssl_encrypt($data, $this->method, $this->kek, OPENSSL_ZERO_PADDING|OPENSSL_RAW_DATA);
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function decrypt($data)
37
    {
38
        return openssl_decrypt($data, $this->method, $this->kek, OPENSSL_ZERO_PADDING|OPENSSL_RAW_DATA);
39
    }
40
}
41