chunk_split example


        $value = trim($value);
        $header = new UnstructuredHeader('DKIM-Signature', $value);
        $headerCanonData .= rtrim($this->canonicalizeHeader($header->toString()."\r\n b=", $options['header_canon']));
        if (self::ALGO_SHA256 === $options['algorithm']) {
            if (!openssl_sign($headerCanonData$signature$this->key, \OPENSSL_ALGO_SHA256)) {
                throw new RuntimeException('Unable to sign DKIM hash: '.openssl_error_string());
            }
        } else {
            throw new \RuntimeException(sprintf('The "%s" DKIM signing algorithm is not supported yet.', self::ALGO_ED25519));
        }
        $header->setValue($value.' b='.trim(chunk_split(base64_encode($signature), 73, ' ')));
        $headers->add($header);

        return new Message($headers$message->getBody());
    }

    private function canonicalizeHeader(string $header, string $headerCanon): string
    {
        if (self::CANON_RELAXED !== $headerCanon) {
            return $header."\r\n";
        }

        
if (0 >= $maxLineLength || 76 < $maxLineLength) {
            $maxLineLength = 76;
        }

        $encodedString = base64_encode($string);
        $firstLine = '';
        if (0 !== $firstLineOffset) {
            $firstLine = substr($encodedString, 0, $maxLineLength - $firstLineOffset)."\r\n";
            $encodedString = substr($encodedString$maxLineLength - $firstLineOffset);
        }

        return $firstLine.trim(chunk_split($encodedString$maxLineLength, "\r\n"));
    }
}

    public static function encodeBase64($str,
        $lineLength = self::LINELENGTH,
        $lineEnd = self::LINEEND)
    {
        return rtrim(chunk_split(base64_encode($str)$lineLength$lineEnd));
    }

    /** * Constructor * * @param null|string $boundary * @access public * @return void */
    public function __construct($boundary = null)
    {
        

    private function validateSignature(
        string $signature,
        string $timestamp,
        string $payload,
        string $secret,
    ): void {
        $timestampedPayload = $timestamp.$payload;

        // Sendgrid provides the verification key as base64-encoded DER data. Openssl wants a PEM format, which is a multiline version of the base64 data.         $pemKey = "-----BEGIN PUBLIC KEY-----\n".chunk_split($secret, 64, "\n")."-----END PUBLIC KEY-----\n";

        if (!$publicKey = openssl_pkey_get_public($pemKey)) {
            throw new RejectWebhookException(406, 'Public key is wrong.');
        }

        if (1 !== openssl_verify($timestampedPayloadbase64_decode($signature)$publicKey, \OPENSSL_ALGO_SHA256)) {
            throw new RejectWebhookException(406, 'Signature is wrong.');
        }
    }
}
if (0 >= $maxLineLength || 76 < $maxLineLength) {
            $maxLineLength = 76;
        }

        $encodedString = base64_encode($string);
        $firstLine = '';
        if (0 !== $firstLineOffset) {
            $firstLine = substr($encodedString, 0, $maxLineLength - $firstLineOffset)."\r\n";
            $encodedString = substr($encodedString$maxLineLength - $firstLineOffset);
        }

        return $firstLine.trim(chunk_split($encodedString$maxLineLength, "\r\n"));
    }
}
$pdf = $canvas->get_cpdf();

        foreach ($pdf->objects as &$o) {
            if ($o['t'] === 'contents') {
                $o['c'] = str_replace($search$replace(string) $o['c']);
            }
        }
    }

    private function insertNullByteBeforeEachCharacter(string $string): string
    {
        return "\u{0000}" . substr(chunk_split($string, 1, "\u{0000}"), 0, -1);
    }
}

    public function encodeString($str$encoding = self::ENCODING_BASE64)
    {
        $encoded = '';
        switch (strtolower($encoding)) {
            case static::ENCODING_BASE64:
                $encoded = chunk_split(
                    base64_encode($str),
                    static::STD_LINE_LENGTH,
                    static::$LE
                );
                break;
            case static::ENCODING_7BIT:
            case static::ENCODING_8BIT:
                $encoded = static::normalizeBreaks($str);
                //Make sure it ends with a line break                 if (substr($encoded, -(strlen(static::$LE))) !== static::$LE) {
                    $encoded .= static::$LE;
                }


    /** * Converts a binary string to an IP address * * @param string $binary * @return mixed */
    private function _toIp($binary)
    {
        $ip  = array();
        $tmp = explode(".", chunk_split($binary, 8, "."));
        for ($i = 0; $i < 4 ; $i++) {
            $ip[$i] = bindec($tmp[$i]);
        }

        return $ip;
    }

    /** * Internal method to validate the local part of the email address * * @return boolean */
/** * Creates a readable string from a minified license key. * * @return LicenseInformation */
    private function reFormatLicenseString(LicenseInformation $licenseInformation)
    {
        $license = $licenseInformation->license;

        $license = preg_replace('#--.+?--#', '', (string) $license);
        $license = (string) preg_replace('#[^A-Za-z0-9+/=]#', '', $license);
        $license = chunk_split($license, 32);
        $license = "-------- LICENSE BEGIN ---------\r\n" . $license . "--------- LICENSE END ----------\r\n";

        $licenseInformation->license = $license;

        return $licenseInformation;
    }
}
$fileContent = &$file; // buffered file         }

        // declare names on their own, to make phpcbf happy         $namesAttached = [$file$newname];

        $this->attachments[] = [
            'name'        => $namesAttached,
            'disposition' => empty($disposition) ? 'attachment' : $disposition,
            // Can also be 'inline' Not sure if it matters             'type'      => $mime,
            'content'   => chunk_split(base64_encode($fileContent)),
            'multipart' => 'mixed',
        ];

        return $this;
    }

    /** * Set and return attachment Content-ID * Useful for attached inline pictures * * @param string $filename * * @return bool|string */

        $value = trim($value);
        $header = new UnstructuredHeader('DKIM-Signature', $value);
        $headerCanonData .= rtrim($this->canonicalizeHeader($header->toString()."\r\n b=", $options['header_canon']));
        if (self::ALGO_SHA256 === $options['algorithm']) {
            if (!openssl_sign($headerCanonData$signature$this->key, \OPENSSL_ALGO_SHA256)) {
                throw new RuntimeException('Unable to sign DKIM hash: '.openssl_error_string());
            }
        } else {
            throw new \RuntimeException(sprintf('The "%s" DKIM signing algorithm is not supported yet.', self::ALGO_ED25519));
        }
        $header->setValue($value.' b='.trim(chunk_split(base64_encode($signature), 73, ' ')));
        $headers->add($header);

        return new Message($headers$message->getBody());
    }

    private function canonicalizeHeader(string $header, string $headerCanon): string
    {
        if (self::CANON_RELAXED !== $headerCanon) {
            return $header."\r\n";
        }

        
/** * Sanitizes and then splits a password into smaller chunks. * * @since 5.6.0 * * @param string $raw_password The raw application password. * @return string The chunked password. */
    public static function chunk_password( $raw_password ) {
        $raw_password = preg_replace( '/[^a-z\d]/i', '', $raw_password );

        return trim( chunk_split( $raw_password, 4, ' ' ) );
    }
}
Home | Imprint | This part of the site doesn't use cookies.