Question: what do I need to do to get the Base64String of the entire certificate (including private key) in Powershell?
Case: On Windows, I have a certificate on my User store.
In Powershell I do the following:
$cert = Get-ChildItem Cert:\CurrentUser\My | Where-Object { $_.Subject -match "cert-subject" }
$certdata = [System.Convert]::ToBase64String($cert.RawData)
$str = ConvertTo-SecureString -String $certdata -AsPlainText -Force
Now in $str I find only the Public Key - the private key part is missing.
I am trying to upload $str as a secret in Azure KeyVault using:
Set-AzureKeyVaultSecret `
-VaultName $VaultName `
-Name $SecretName `
-SecretValue $certsecret `
-ContentType 'application/x-pkcs12' `
-Expires $cert.NotAfter `
-NotBefore $cert.NotBefore
but the result is that this is a file that contains only the private key.
If I save the certificate manually from the local store and export the private key to a file, then use the Azure portal, I can upload the full cert pair.
Thx!