As title, I am able to add networkService account to a .pfx certificate I have installed on my local machine. I do not install the .pfx with any password for private key.
Powershell solution:
$cert = Get-ChildItem -Path cert:\LocalMachine\My | ? -FilterScript { $PSItem.Subject -like "*<MyCertMatch>*" }
$keyPath = Join-Path -Path $env:ProgramData -ChildPath "\Microsoft\Crypto\RSA\MachineKeys"
$keyContainerName = $cert.PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
$keyFullPath = Join-Path -Path $keyPath -ChildPath $keyName
# Here I can get-acl: using get-acl and see results
Now when I have the fullPath I can add a new acl. However, this (above) I get stuck on in c#:
if (cert.Subject.Contains("<myCertMatch>"))
{
RSACryptoServiceProvider rsa = cert.PrivateKey as RSACryptoServiceProvider;
if (rsa != null)
{
// Add logic here
}
}
Here rsa defaults to null
but cert.PrivateKey
is not null
, thus I cannot retrieve container or any ACL.
I'd appreciate any input/feedback.
Thanks,