Signing key is not loaded
Publicado por Aaron (2 intervenciones) el 04/02/2009 17:26:10
Hola a todos, Este es mi primer mensaje en el foro y es que estoy desesperado.
Tengo una web en ASP.NET que tiene que firmar digitalmente un XML, el casoe s que lo he desarrollado i ha funcionado correctamente, lo malo es uqe al ponerlo en el servidor de producción del cliente me da el siguiente error:
Server Error in '/Servei Passarela' Application.
Signing key is not loaded.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: Signing key is not loaded.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[CryptographicException: Signing key is not loaded.] System.Security.Cryptography.Xml.SignedXml.ComputeSignature() +339 _Default.FirmarXML(XmlDocument& documento, X509Certificate2 certificado) +139 _Default.Page_Load(Object sender, EventArgs e) +858 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
Y este es el codigo que firma el XML
private static void FirmarXML(ref XmlDocument documento, X509Certificate2 certificado)
{
SignedXml sig = new SignedXml(documento);
//Recuperamos la clave privada para firmar
sig.SigningKey = certificado.PrivateKey;
Reference reference = new Reference();
//No le asignamos ninguna Url en concreto al querer firmar doto el doc.
reference.Uri = "";
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
//Añadimos la transformación a la referencia
reference.AddTransform(env);
sig.AddReference(reference);
sig.ComputeSignature();
XmlElement xmlDigitalSignature = sig.GetXml();
documento.DocumentElement.AppendChild(documento.ImportNode(xmlDigitalSignature, true));
}
Alguna idea de que puede estar pasando? agradeceria enormemente qualquier ayuda.
Gracias.
Tengo una web en ASP.NET que tiene que firmar digitalmente un XML, el casoe s que lo he desarrollado i ha funcionado correctamente, lo malo es uqe al ponerlo en el servidor de producción del cliente me da el siguiente error:
Server Error in '/Servei Passarela' Application.
Signing key is not loaded.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.Cryptography.CryptographicException: Signing key is not loaded.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[CryptographicException: Signing key is not loaded.] System.Security.Cryptography.Xml.SignedXml.ComputeSignature() +339 _Default.FirmarXML(XmlDocument& documento, X509Certificate2 certificado) +139 _Default.Page_Load(Object sender, EventArgs e) +858 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.42
Y este es el codigo que firma el XML
private static void FirmarXML(ref XmlDocument documento, X509Certificate2 certificado)
{
SignedXml sig = new SignedXml(documento);
//Recuperamos la clave privada para firmar
sig.SigningKey = certificado.PrivateKey;
Reference reference = new Reference();
//No le asignamos ninguna Url en concreto al querer firmar doto el doc.
reference.Uri = "";
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
//Añadimos la transformación a la referencia
reference.AddTransform(env);
sig.AddReference(reference);
sig.ComputeSignature();
XmlElement xmlDigitalSignature = sig.GetXml();
documento.DocumentElement.AppendChild(documento.ImportNode(xmlDigitalSignature, true));
}
Alguna idea de que puede estar pasando? agradeceria enormemente qualquier ayuda.
Gracias.
Valora esta pregunta


0