2020-11-10

Convert Certification (.cer / .crt) to Base64

Convert-CertificateBinaryToBase64 -Sourcefile 'C:\Cert\Certification.cer' -DestinationFile 'C:\Cert\CertificationCER.txt'

Convert-CertificateBinaryToBase64 -Sourcefile 'C:\Cert\Certification.crt' -DestinationFile 'C:\Cert\CertificationCRT.txt'

function Convert-CertificateBinaryToBase64 {
Param( [String]$SourceFile, [String]$DestinationFile )
$Cert = Get-Content "$SourceFile" -Encoding Byte
$Content = @(

    '-----BEGIN CERTIFICATE-----'
    [System.Convert]::ToBase64String($Cert, 'InsertLineBreaks')
    '-----END CERTIFICATE-----'
);
$Content | Out-File -FilePath "$DestinationFile" -Encoding ASCII
};

沒有留言:

張貼留言