Salut

Je suis entrain de développer un générateur des licences, j'ai choisi la signature numérique pour générer les licences. Pour se faire j'ai besoin d'un certificat et d'une clé privée. J'ai utilisé l'outil openssl pour créer une autorité de certification et par la suite pour générer un certificat pour mon serveur

J'ai obtenu à la fin les fichiers sivants:CA_crt.pem ,CA_crt.pem, client_crt.pem et client_pvk.pem.
Au niveau de mon application (en c#), je dois faire appel à la clé privée du serveur (client_pvk.pem) pour signer une chaine de caractères, j'ai trouvé cette méthode:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
private byte[] SignCertificate(string text)
{
// Open certificate store of current user
X509Store my = new X509Store(StoreName.My, StoreLocation.CurrentUser);
my.Open(OpenFlags.ReadOnly);
 
// Look for the certificate with specific subject 
RSACryptoServiceProvider csp = null;
foreach (X509Certificate2 cert in my.Certificates)
{
if (cert.Subject.Contains("CN=WINGROUP\\micwein"))
{
// retrieve private key
csp = (RSACryptoServiceProvider)cert.PrivateKey;
}
}
if (csp == null)
{
throw new Exception("Valid certificate was not found");
}
 
// Hash the data
SHA1Managed sha1 = new SHA1Managed();
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] data = encoding.GetBytes(text);
byte[] hash = sha1.ComputeHash(data);
 
// Sign the hash
return csp.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
}
J'ai compris que le certificat de mon serveur doit être installé dans le magasin de certificat de la machine.

Y a t-il d'autres solutions pour pouvoir signer un message par la clé privée générée par openssl (client_pvk.pem)? J'ai besoin d'un code c#.

Sinon, comment je peux ajouter un certificat dans le magasin de certificat de la machine à partir d'un fichier d'extension .pem afin de pouvoir utiliser la méthode "SignCertificate" décrite ci-dessus.

Merci d'avance pour votre aide.
Bonne journée.