Encryptor::encrypt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
3
namespace Codecraft63\CertsignLogin;
4
5
class Encryptor
6
{
7
8
    use Util;
9
10
    /**
11
     * Encrypt text using certsign login private key.
12
     *
13
     * @param string $input
14
     * @param string $key
15
     * @throws \Exception
16
     * @return string
17
     */
18
    public static function encrypt(string $input, string $key): string
19
    {
20
        list($cipher, $iv_size) = self::getCipher();
21
        $iv = substr($key, 0, $iv_size);
22
        $key = substr($key, 0, $iv_size);
23
24
        mcrypt_generic_init($cipher, $key, $iv);
25
26
        $data = mcrypt_generic($cipher, $input);
27
        $data = str_replace("certplus", "\\+", str_replace("(\r\n|\n)", "", $data));
28
29
        self::finalizeCipher($cipher);
30
31
        return base64_encode($data);
32
    }
33
}
34