powershell - Converting base64 string to X509 certifcate -


can please me following question. use powershell , far have figured out how take x509 certificate flat file e.g. cert.cer , concert base64 string storage (e.g. in database string etc.) , convert again system.security.cryptography.x509certificates.x509certificate2 object

see code below far

$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)) 

now thing want write object $obj3 file system flat file (e.g. cert.cer) readable/usable original certificate. if use | out-file c:\temp2\cert.cer etc... file bigger original file , not readable (e.g. not open normal cert file). assume encoding issue when writing out object file system (i believe cert files asn 1 encode binary files)

can me achieve please, in advance.

e brant

the problem pewrshell unicode default, while cryptoapi decoder expects ascii encoding (where each character encoded using 1 byte). achieve this, add -encoding ascii paramter out-file cmdlet.

btw, there no need store certificate file in binary format. cryptoapi supports certificate files in base64 format. since .net relies on cryptoapi, there not comatibility problems.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -