src/Certificate.php
/**
     * Convert X.509 DER base64 or X.509 DER to X.509 PEM
     *
     * @param string $contents can be a certificate format X.509 DER or X.509 DER base64
     * @return string
     */
Convert X.509 DER base64 or X.509 DER to X.509 PEM
@param string $contents can be a certificate format X.509 DER or X.509 DER base64
@return string
Convert X . 509 DER base64 or X . 509 DER to X . 509 PEM @param string $contents can be a certificate format X . 509 DER or X . 509 DER base64 @return string
public static function convertDerToPem(string $contents): string
    {
        if ($contents !== base64_encode(base64_decode($contents, true) ?: '')) {
            $contents = base64_encode($contents);
        }
        return '-----BEGIN CERTIFICATE-----' . PHP_EOL
            . chunk_split($contents, 64, PHP_EOL)
            . '-----END CERTIFICATE-----';
    }
public static function convertDerToPem ( string $ contents ) : string { if ( $ contents !== base64_encode ( base64_decode ( $ contents , true ) ? : '' ) ) { $ contents = base64_encode ( $ contents ) ; } return '-----BEGIN CERTIFICATE-----' . PHP_EOL . chunk_split ( $ contents , 64 , PHP_EOL ) . '-----END CERTIFICATE-----' ; }
Convert X.509 DER base64 or X.509 DER to X.509 PEM
 @param string $contents can be a certificate format X.509 DER or X.509 DER base64
 @return string
Convert X . 509 DER base64 or X . 509 DER to X . 509 PEM @param string $contents can be a certificate format X . 509 DER or X . 509 DER base64 @return string
// effectively compare that all the content is base64, if it isn't then encode it