McryptStrategy::createIv()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * File McryptStrategy.php
4
 */
5
6
namespace Tebru\AesEncryption\Strategy;
7
8
/**
9
 * Class McryptStrategy
10
 *
11
 * @author Nate Brunette <[email protected]>
12
 */
13
class McryptStrategy extends AesEncryptionStrategy
14
{
15
    /**
16
     * Create an initialization vector
17
     *
18
     * @return string
19
     */
20
    public function createIv()
21
    {
22
        return mcrypt_create_iv($this->getIvSize(), MCRYPT_DEV_URANDOM);
23
    }
24
25
    /**
26
     * Get the size of the IV
27
     *
28
     * @return int
29
     */
30
    public function getIvSize()
31
    {
32
        return mcrypt_get_iv_size(self::ENCRYPTION_CIPHER, self::ENCRYPTION_MODE);
33
    }
34
35
    /**
36
     * Encrypt data
37
     *
38
     * @param mixed $data
39
     * @param string $iv
40
     * @return mixed
41
     */
42
    public function encryptData($data, $iv)
43
    {
44
        return mcrypt_encrypt(self::ENCRYPTION_CIPHER, $this->getKey(), $data, self::ENCRYPTION_MODE, $iv);
45
    }
46
47
    /**
48
     * Decrypt data
49
     *
50
     * @param $data
51
     * @param $iv
52
     * @return mixed
53
     */
54
    public function decryptData($data, $iv)
55
    {
56
        return trim(mcrypt_decrypt(self::ENCRYPTION_CIPHER, $this->getKey(), $data, self::ENCRYPTION_MODE, $iv));
57
    }
58
}
59