Completed
Push — master ( 1a48b1...65cd04 )
by Ramon
02:01
created

Decrypto::decrypt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 17
Ratio 100 %

Importance

Changes 0
Metric Value
dl 17
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 2
1
<?php
2
3
namespace Codecraft63\CertsignLogin;
4
5
6 View Code Duplication
class Decrypto
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
7
{
8
    use Util;
9
10
    /**
11
     * Decrypt text using certsign login private key.
12
     *
13
     * @param string $text
14
     * @param string $key
15
     * @throws \Exception
16
     * @return string
17
     */
18
    public static function decrypt(string $text, string $key): string
19
    {
20
        $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
21
        $cipher_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
22
        $iv = substr($key, 0, $cipher_size);
23
24
        mcrypt_generic_init($cipher, $key, $iv);
25
26
        $text = base64_decode(str_replace("certplus", "\\+", $text));
27
        $text = self::pkcs5_pad($text, $cipher_size);
0 ignored issues
show
Documentation introduced by
$cipher_size is of type integer, but the function expects a object<Codecraft63\CertsignLogin\integer>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
29
        $decrypted_text = mdecrypt_generic($cipher, $text);
30
        mcrypt_generic_deinit($cipher);
31
        mcrypt_module_close($cipher);
32
33
        return $decrypted_text;
34
    }
35
}
36