Jump to content

RemoteConnector


ulfwil

Recommended Posts

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


  • 2 weeks later...
  • Most Valued User

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


Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and have taken note of our Privacy Policy.
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.