ulfwil Posted October 24, 2016 #1 Share Posted October 24, 2016 Hi, anyone knowing how to generate pfx-files from powershell? I guess something like $type=[System.Security.Cryptography.X509Certificates.X509ContentType]::pfx $cert=Get-IpPbxClientCertificate -UserEntry $(get-ippbxuser -username 'Ulf Wilhelmsson') $bytes=$cert.Export($type) # Eventually $bytes=$cert.Export($type,$password) [system.convert]::ToBase64String($bytes) > file.pfx But I get errors on row => $bytes=$cert.Export($type) Exception calling "Export" with "1" argument(s): "Key not valid for use in specified state. Link to comment Share on other sites More sharing options...
Most Valued User Martin Posted November 8, 2016 Most Valued User #2 Share Posted November 8, 2016 Hi, you should use something like this: Export-PfxCertificate -Cert $Cert -FilePath .\pfxtest.pfx -Password (convertto-securestring -string 'mysecretpassword' -AsPlainText -Force) However, the Get-IpPbxClientCertificate cmdlet has a bug causing the returned certificate object to to not have the "exportable" flag set. We'll have a bugfix in R4. If you can't wait, here's a workaround: $stringCertificate = "" $adminFacade.GetClientCertificate($UserEntry.UserId, [ref] $stringCertificate) $byteCertificate = [System.Convert]::FromBase64String($stringCertificate) $certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 $certificate.Import($byteCertificate, "", [Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable) Export-PfxCertificate -Cert $Certificate -FilePath .\Desktop\pfxtest.pfx -Password (convertto-securestring -string 'secret' -AsPlainText -Force) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.