Here is a code snippet that demonstrates how we can find a certificate in the certificate store, then sign with it's private key.
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store("My", "CurrentUser")
$store.Open('MaxAllowed');
$col = $store.Certificates.Find("FindByThumbprint", "2eacbf2444f793edd56185ad1055eb61b6230bad", $false);
$cert = $col[0];
$rsaPrivateKey = $cert.PrivateKey;
[byte[]] $data = 65,66,67,90
$signature = $rsaPrivateKey.SignData($data, [Security.Cryptography.HashAlgorithmName]::SHA256, [Security.Cryptography.RSASignaturePadding]::Pkcs1)
Write-Host $cert.PrivateKey
Tags
PowerShell