Ich habe ein C# -Programm (auf .NET 8), das Daten mit einem RSA-Schlüssel unterzeichnet, das in Windows Cert-/Keystore gespeichert ist. Der Schlüssel wurde mit Windows certmgr.msc in den "Personal" -Speor importiert. Die importierende Option "hohe Sicherheit" (Kennwort erforderlich) + Virtualisierungsbasierte Sicherheit (die Schlüssel nicht exportierbar) wurden im Dialogfeld Importieren aktiviert. < /P>
static void Main()
{
string subjectName = "selfsigned";
using (var store = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
store.Open(OpenFlags.ReadOnly);
var certs = store.Certificates.Find(X509FindType.FindBySubjectName,
subjectName,validOnly: false);
if (certs.Count == 0)
{
Console.WriteLine($"Certificate containing subject '{subjectName}' not found.");
return;
}
X509Certificate2 cert = certs[0];
using (RSA rsa = cert.GetRSAPrivateKey()) // fails here
{
if (rsa == null)
{
Console.WriteLine("Certificate does not have an RSA private key.");
return;
}
// ... do something with the key
}
}
}
< /code>
Der Code funktioniert auf einem Windows 10 -System (22H2, neuesten Updates). Wenn Windows das Dialogfeld "Kennworteintrag" anzeigt, kann ich den privaten Schlüssel verwenden, z. Zum Signieren von Daten. Das Dialogfeld "Passworteintrag" wird nie angezeigt. Das gleiche gilt für ein zweites Gewinn 11 -Heimsystem. System.security.cryptography.cnghelpers.getProperty (SafeCryPHandle NcryptHandle, String PropertyName, CngPropertyoptions -Optionen)
at system.security.cryptography.cngkey.get_algorithmsorup ()
at at AT_Algorithmebroup ()
at at at A at at at at at at at at at at at at at at at at at at at at at at at at at at at at at A at At, Atergkey. System.security.cryptography.rsacng.set_key (cngkey value)
at system.security.cryptographie System.Security.Cryptography.X509Certificates.CertificatePal.c.b__68_1(CngKey cngKey)
at System.Security.Cryptography.X509Certificates.CertificatePal.GetPrivateKey[T](Func2 createCsp, Func< /code> 2 createCng)
at system.security.cryptography.x509certificates.CertificateExtensionscommon.getPrivateKey [t] (x509Certificate2 -Zertifikat, Predicate`1 Matchescontens)
< /> < /> < /> < /P.) < /p> < /> < /> < /> < /PLOCTE> < /PROGRAM. /> Ist dies ein Fehler von Windows 11 oder ist das Windows 11 -System so konfiguriert, dass die Verwendung solcher Schlüssel verhindert? Nur wenn Sie ein zusätzliches Passwort festlegen, fällt immer unter Windows 11 fehl.
Windows 11: Private Schlüssel nicht verwendbar, wenn VBS + High Security (Passwort) geschützt werden kann ⇐ C#
-
- Similar Topics
- Replies
- Views
- Last post