Ici, vous utilisez la clé (publique/privée) du certificat.
Option 1)
X509Certificate2 cert = RetrieveCertificate("abcd");
var key = cert.PrivateKey;
private static X509Certificate2 RetrieveCertificateFromStore(string certificateName)
{
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
store.Open(OpenFlags.OpenExistingOnly);
var cert = store.Certificates.OfType<X509Certificate2>().AsEnumerable().FirstOrDefault(c => c.FriendlyName == certificateName);
return cert;
}
Ou Récupérer certificat de fichier:
private static X509Certificate2 RetrieveCertificateFromFile(string certPath)
{
// string certPath = @"C:\Certificates\myCert.pfx";
string certPass = "mycertPass";
// Create a collection object and populate it using the PFX file
X509Certificate2Collection collection = new X509Certificate2Collection();
collection.Import(certPath, certPass, X509KeyStorageFlags.PersistKeySet);
// Instead of foreach you can directly retrieve the certificate from collection as well.
foreach (X509Certificate2 cert in collection)
{
// Import the certificates into X509Store objects
return cert;
}
return null;
}
Option 2)
RSACryptoServiceProvider key = RetrieveKey(cert, EnumKeyType.Private);
Je crois qu'un nu 'RSACryptoServiceProvider' est trop moins d'avoir un 'X509Certificate2'. Pourriez-vous éventuellement développer votre question et ajouter des détails sur la façon dont vous achetez réellement le fournisseur de chiffrement et si votre 'SignXmlFile' attend moins que le' X509Certificate2 'à part entière? –
Dupliquer de https://stackoverflow.com/questions/1195728/in-c-sign-an-xml-with-ax-509-certificate-and-check-the-signature –