PureGremlin

Convert to Base64

Mar 23rd, 2022 (edited)
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. Converts a byte encoded file to Base64 encoding to transfer data by text, like certificates
  3. Mimics function of openssl base64 -in certificate.pfx -out certificate.p12
  4. #>
  5.  
  6. function Convert-ByteToBase64 {
  7. param($in,$out)
  8.  
  9. $fileContentBytes = get-content $in -Encoding Byte
  10.  
  11. "-----BEGIN CERTIFICATE-----" |Out-File $out
  12. [regex]::split(([System.Convert]::ToBase64String($fileContentBytes)),  '(.{65})') | ? {$_} | out-file $out -append
  13. "-----END CERTIFICATE-----" | out-file $out -append
  14. }
Add Comment
Please, Sign In to add comment