Buen día comunidad, tengo el siguiente problema.
Tengo lo siguiente:
String clientKeyStore = "cliente.jks"; String serverKeyStore = "clientedes.cer";
Tengo un webservices WSDL basado en jax-ws.
Se carga un xml el cual se le ingresa el certificado ("clientedes.cer")
X509Store store = new X509Store(clientKeyAlias, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite);
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, certSubNamer, true);
X509Certificate2Collection currentCerts = col.Find(X509FindType.FindByTimeValid, DateTime.Now, false);
return currentCerts[0];
store.Close();
XmlDocument doc = new XmlDocument();
string XmlFileName = "C:Instrucciones.xml";
doc.Load(XmlFileName);
doc.PreserveWhitespace = false;
if (!(doc.FirstChild is XmlDeclaration))
{
XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", string.Empty);
doc.InsertBefore(declaration, doc.FirstChild);
CustomSignedXml signedXml = new CustomSignedXml(doc);
// Se agrega el certificado cliente.cer
signedXml.SigningKey =cert.PrivateKey;
}
KeyInfo keyInfo = new KeyInfo();
keyInfo.Id = keyInfoRefId;
Console.WriteLine("keyInfo.Id: {0}", keyInfo.Id);
// Load the certificate into a KeyInfoX509Data object
// and add it to the KeyInfo object.
KeyInfoX509Data keyInfoData = new KeyInfoX509Data();
keyInfoData.AddCertificate(cert);
keyInfo.AddClause(keyInfoData);
Console.WriteLine("keyInfo: {0}", keyInfoData);
// Add the KeyInfo object to the SignedXml object.
signedXml.KeyInfo = keyInfo;
Console.WriteLine("signedXml: {0}", signedXml.SigningKey);
// Create a reference to be signed.
Reference reference = new Reference();
reference.Uri = "";
// Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
// Add the reference to the SignedXml object.
signedXml.AddReference(reference);
Reference reference2 = new Reference();
reference2.Uri = "#" + keyInfoRefId;
signedXml.AddReference(reference2);
// Add the Signature Id
signedXml.Signature.Id = Signature; // problema justo al ingresar la llave jks
// Compute the signature.
signedXml.ComputeSignature();
al llegar a ese punto me suelta el siguiente error.
Excepción producida: 'System.Security.Cryptography.CryptographicException' en ContingenciaV5.dll Excepción no controlada del tipo 'System.Security.Cryptography.CryptographicException' en ContingenciaV5.dll Signing key is not loaded.
Esto lo trato de hacer en C#. ero no encuentro como cargarle la firma después de haberle ingresado el certificado.