diff --git a/src/Item/Get-CredentialStoreItem.ps1 b/src/Item/Get-CredentialStoreItem.ps1 index 5f529fa..12f06eb 100644 --- a/src/Item/Get-CredentialStoreItem.ps1 +++ b/src/Item/Get-CredentialStoreItem.ps1 @@ -87,7 +87,12 @@ function Get-CredentialStoreItem { $CSMembers = Get-Member -InputObject $CS # Let's first check if the given remote host exists as object property if (($CSMembers.MemberType -eq "NoteProperty") -and ($CSMembers.Name -contains $CredentialName)) { - $Cert = Get-CSCertificate -Type $CS.Type -Thumbprint $CS.Thumbprint + if ($null -eq $CS.PfxCertificate) { + $Cert = Get-CSCertificate -Type $CS.Type -Thumbprint $CS.Thumbprint + } + else { + $Cert = Get-PfxCertificate -FilePath $CS.PfxCertificate -ErrorAction Stop + } $DecryptedKey = $Cert.PrivateKey.Decrypt( [Convert]::FromBase64String($CS.$CredentialName.EncryptedKey), [System.Security.Cryptography.RSAEncryptionPadding]::Pkcs1 diff --git a/src/Item/New-CredentialStoreItem.ps1 b/src/Item/New-CredentialStoreItem.ps1 index a52c1b9..6659302 100644 --- a/src/Item/New-CredentialStoreItem.ps1 +++ b/src/Item/New-CredentialStoreItem.ps1 @@ -116,7 +116,12 @@ function New-CredentialStoreItem { } if ($Credential.UserName) { - $Cert = Get-CSCertificate -Type $CSContent.Type -Thumbprint $CSContent.Thumbprint + if ($null -eq $CSContent.PfxCertificate) { + $Cert = Get-CSCertificate -Type $CSContent.Type -Thumbprint $CSContent.Thumbprint + } + else { + $Cert = Get-PfxCertificate -FilePath $CSContent.PfxCertificate -ErrorAction Stop + } if (Get-Member -InputObject $CSContent -Name $CredentialName -Membertype Properties) { $MessageParams = @{ diff --git a/src/Item/Set-CredentialStoreItem.ps1 b/src/Item/Set-CredentialStoreItem.ps1 index 7df7845..738b9fb 100644 --- a/src/Item/Set-CredentialStoreItem.ps1 +++ b/src/Item/Set-CredentialStoreItem.ps1 @@ -102,7 +102,12 @@ function Set-CredentialStoreItem { } if ($Credential.UserName) { - $Cert = Get-CSCertificate -Type $CSContent.Type -Thumbprint $CSContent.Thumbprint + if ($null -eq $CSContent.PfxCertificate) { + $Cert = Get-CSCertificate -Type $CSContent.Type -Thumbprint $CSContent.Thumbprint + } + else { + $Cert = Get-PfxCertificate -FilePath $CSContent.PfxCertificate -ErrorAction Stop + } if (Get-Member -InputObject $CSContent -Name $CredentialName -Membertype Properties) { $RSAKey = Get-RandomAESKey