Я хочу подписать XML с сертификатом X509 в C # Webservice.
Получить сертификат thubmprint из x509Store
private static bool GetCert(string thumbprint)
{
GlobalCert = new X509Certificate2();
X509Store x509Store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
x509Store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection certCollection = x509Store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
x509Store.Close();
if (certCollection.Count == 0) {
return false;
}
foreach (X509Certificate2 cert in certCollection)
{
GlobalCert = cert;
}
return true;
}
Подписание xml (пользователь должен ввести свой PIN-код для сертификата)
private static void SignXml(XmlDocument xmlDoc)
{
SignedXml signedXml = new SignedXml(xmlDoc);
Reference reference = new Reference();
reference.Uri = "#signedContent";
signedXml.AddReference(reference);
signedXml.SignedInfo.SignatureMethod = SignedXml.XmlDsigRSASHA1Url;
signedXml.SignedInfo.CanonicalizationMethod = SignedXml.XmlDsigC14NWithCommentsTransformUrl;
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new KeyInfoX509Data(GlobalCert));
signedXml.KeyInfo = keyInfo;
if (GlobalCert.HasPrivateKey)
{
signedXml.SigningKey = GlobalCert.PrivateKey;
}
else
{
signedXml.SigningKey = GlobalCert.GetRSAPrivateKey();
}
signedXml.ComputeSignature();//Here the prompt for PIN pops up
XmlElement xmlDigitalSignature = signedXml.GetXml();
xmlDoc.FirstChild.FirstChild.AppendChild(xmlDoc.ImportNode(xmlDigitalSignature, true));
}
POST xml
Отлично ... Работает ...но только в DEBUG (localhost: 2626).
Когда я публикую веб-сервис (localhost: 8080), не появляется подсказка для запроса PIN-кода.
Для My AppPool Identity установлено значение LocalService.
Любая помощь будет оценена!