ajouter automatiquement un certificat sous un compact frameWork
Bonjour tout le monde,
Je galère ça fait deux semaine pour l'ajout d'un certificat client dans mon Windows CE :cry:, je m'explique: j'ai un certificat client que je dois ajouter automatiquement sous internet explorer afin de pourvoir ouvrir un https, travaillant sou c# j'ai essayé cetet fonction (qui ne marche pas bien évidement):
Code:
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 31
|
public static void ImportCert(string Path)
{
//Ouverture du magazin 'MY'
X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
X509CertificateCollection myCollection = store.Certificates;
//convertir le certificat en tableau de Bytes
byte[] certByte = GetFile(Path);
//Création de l'objet x509 à partir du tableau de bytes
X509Certificate x509 = new X509Certificate(certByte);
//Ajout du certificat à la collection du magasin 'MY'
myCollection.Add(x509);
IntPtr cert_MY_store = CertOpenStore(new IntPtr(CERT_STORE_PROV_SYSTEM_W),
0,
IntPtr.Zero,
CERT_SYSTEM_STORE_CURRENT_USER,
"MY");
IntPtr hCertCntxt = IntPtr.Zero;
uint b = CertCreateCertificateContext(X509_ASN_ENCODING, certByte, (uint)certByte.Length);
int i = CertAddCertificateContextToStore(cert_MY_store, hCertCntxt, (int)CERT_STORE_ADD_REPLACE_EXISTING, IntPtr.Zero);
//ajouter au registre
Microsoft.Win32.RegistryKey oReg = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Comm\\Security\\SystemCertificates\\my\\Certificates\\6B314720F126EFE681EF72EACFCE477E83D3B9D0");
oReg.SetValue("Blob", certByte);
} |
Est ce qu'il y a quelqu'un qui pourra m'aider???
Amicalement