Comment puis-je charger des certificats clients à partir d'un magasin personnel à l'aide d'ASP.NET?Comment puis-je charger des certificats clients à partir d'un magasin personnel à l'aide d'ASP.NET?
Si c'est possible, puis-je crypter des données avec lui?
Pour cela j'ai créé une application dans ASP.NET 2.0 qui récupère tous les certificats installés dans le magasin de certificats client (personal) pour créer avec lui une signature numérique.
mais cela ne fonctionne pas, et je ne sais pas quel est le problème
// ...
using System.Security.Cryptography.X509Certificates;
namespace WebApplication4
{
public partial class _Default : System.Web.UI.Page
{
public static string ToHexString(byte[] bytes)
{
// ...
}
protected void btnSignature_Click(object sender, EventArgs e)
{
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.OpenExistingOnly);
X509Certificate2Collection certificates = store.Certificates;
int a = certificates.Count;
lbCertCount.Text = System.Convert.ToString(a);
if (a > 0)
{
X509Certificate2 certificate = certificates[1];
string publicKey = certificate.GetPublicKeyString();
lbMypublicKey.Text = publicKey + "<br/>";
// AsymmetricAlgorithm privateKey = certificate.PrivateKey;
RSACryptoServiceProvider privateKey = certificate.PrivateKey as RSACryptoServiceProvider;
// test message
byte[] buffer = Encoding.Default.GetBytes("Welcome");
byte[] signature = privateKey.SignData(buffer, new SHA1Managed());
string me = ToHexString(signature);
lbSignature.Text = me;
RSACryptoServiceProvider publicKey1 = certificate.PublicKey.Key as RSACryptoServiceProvider;
bool verify = publicKey1.VerifyData(buffer, new SHA1Managed(), signature);
if (verify == true)
{
lbControl.Text = "Signature valid";
}
else
{
lbControl.Text = "Signature not Valid";
}
}
}
}
}
Essayez-vous de charger le certificat visiteurs ou un certificat pour un compte d'utilisateur sur le serveur? –
Je tente de charger le certificat des visiteurs, NB: tous mes visiteurs sont dans le réseau intranet et tous sont connectés sur le répertoire actif –
Ok. Comment authentifiez-vous vos utilisateurs? Sont-ils usurpés? –