title: Converting base64 string to X509 certifcate
body: <p>I use PowerShell and thus far I have figured out how to take a X509 certificate flat file e.g. Cert.cer and concert it to a Base64 string for storage (e.g. in a database as a string etc.) and then convert it back again into a System.Security.Cryptography.X509Certificates.X509Certificate2 object </p>
  
  <p>See my code below so far:</p>
  
  <pre><code>$CertifcateFileFullPath = "C:\temp\cert.cer"
  $Cert = new-object security.cryptography.x509certificates.x509certificate2 -ArgumentList $CertifcateFileFullPath
  
  $Obj2 = [System.Convert]::ToBase64String($Cert.RawData)
  
  $Obj3 = [System.Security.Cryptography.X509Certificates.X509Certificate2]([System.Convert]::FromBase64String($Obj2))
  </code></pre>
  
  <p>Now the thing is I want to write the object <code>$obj3</code> back to the file system as a flat file (e.g. Cert.cer) which is readable/usable as the original certificate.</p>
  
  <p>If I use | out-file C:\Temp2\Cert.cer   etc... I get a file which is much bigger than the original file and not readable (e.g. does not open as a normal cert file). I assume the encoding is the issue when writing out the object to the file system (I believe cert files are ASN 1 encode binary files) </p>