ASP.NET - Signing key is not loaded

 
Vista:

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.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Signing key is not loaded

Publicado por Aarón (2 intervenciones) el 04/02/2009 17:37:54
Me deje de explicar come creo el objeto certificat:

X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
RSACryptoServiceProvider.UseMachineKeyStore = true;
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection certCollection = store.Certificates;
X509Certificate2 certificat = new X509Certificate2();
certificat = certCollection[0];
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Signing key is not loaded

Publicado por Chentefx (1 intervención) el 05/10/2022 23:12:04
Como lograste solventar el problema, del firmado digital?

se utiliza el *.jks o el *.cer?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Juan Arturo
Val: 6
Ha aumentado su posición en 5 puestos en ASP.NET (en relación al último mes)
Gráfica de ASP.NET

RE:Signing key is not loaded

Publicado por Juan Arturo (7 intervenciones) el 03/11/2022 07:30:12
Para firmar un XML como por ejemplo para un CFDI (mexico), puedes usar el .CER y .KEY (con el pwd de .key), Para un ejemplo busca en google "opensslkey.cs" que es codigo fuente que permite emplear dichos archivos y luego aplicar el SHA256
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar