Jose\KeyConverter\KeyConverter::decodePem PHP Method

decodePem() private static method

private static decodePem ( string $pem, array $matches, null | string $password = null ) : string
$pem string
$matches array
$password null | string
return string
    private static function decodePem($pem, array $matches, $password = null)
    {
        Assertion::notNull($password, 'Password required for encrypted keys.');
        $iv = pack('H*', trim($matches[2]));
        $iv_sub = mb_substr($iv, 0, 8, '8bit');
        $symkey = pack('H*', md5($password . $iv_sub));
        $symkey .= pack('H*', md5($symkey . $password . $iv_sub));
        $key = preg_replace('#^(?:Proc-Type|DEK-Info): .*#m', '', $pem);
        $ciphertext = base64_decode(preg_replace('#-.*-|\\r|\\n#', '', $key));
        $decoded = openssl_decrypt($ciphertext, strtolower($matches[1]), $symkey, true, $iv);
        $number = preg_match_all('#-{5}.*-{5}#', $pem, $result);
        Assertion::eq($number, 2, 'Unable to load the key');
        $pem = $result[0][0] . PHP_EOL;
        $pem .= chunk_split(base64_encode($decoded), 64);
        $pem .= $result[0][1] . PHP_EOL;
        return $pem;
    }