如何使用ASP.NET從個人商店加載客戶端證書?如何使用ASP.NET從個人商店加載客戶端證書?
如果有可能,我可以用它加密數據嗎?
爲此,我在ASP.NET 2.0中創建了一個應用程序,該應用程序檢索安裝在客戶端證書存儲(個人)中的所有證書以創建數字簽名。
,但它不工作,我不知道什麼是我猜你撞倒了這個ASP.NET應用程序的問題
// ...
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";
}
}
}
}
}
您是否試圖爲服務器上的用戶帳戶加載訪問者證書或證書? –
我嘗試加載訪問者證書,注意:我的所有訪問者都在Intranet網絡中,並且都在活動目錄中登錄 –
好的。你如何驗證你的用戶?他們是否被冒充了? –