Decrypt::token()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 6
c 1
b 1
f 0
dl 0
loc 11
rs 10
cc 4
nc 3
nop 3
1
<?php
2
3
namespace Mfonte\Base62x\Encryption\Cypher;
4
5
class Decrypt
6
{
7
    public static function token($data, $method, $key)
8
    {
9
        $iv_strlen = 2 * Bytes::iv($method);
10
        if (preg_match('/^(.{'.$iv_strlen.'})(.+)$/', $data, $regs)) {
11
            list(, $iv, $crypted_string) = $regs;
12
            if (ctype_xdigit($iv) && mb_strlen($iv) % 2 == 0) {
13
                return openssl_decrypt($crypted_string, $method, $key, 0, hex2bin($iv));
14
            }
15
        }
16
17
        return false; // failed to decrypt
18
    }
19
}
20