Hi
I have been using an Oleobject to use a C# DLL that signs XMLs required in Latin America, for invoicing. In the specific case using XADES-EPES.
The PB code looks like: li_rc = loo.ConnectToNewObject("CFeldan_FE.ClassMain"). With the try catch, etc.
That DLL contains functions to sign an XML and make the correspoding POST for the invoice, BUT requieres to use regasm on all client computers.
Looking to avoid the last, I started testing the .DDL import. With the new 2022R2.
The DLL is imported, I can call the functions, but it does not sign. Does anyone has an idea or similar cases for possible solutions?
I will try to detail the case bellow and the error:
C# requires references to BouncyCastle.dll and FirmaXadesNet.dll, both public
Code is: (bold is the line that returns the error only if the .DLL es imported in PB)
public void FirmaXML_Xades(string pathXML, string archivo_firmado, string certificado, string pin ,string NumeroReceptor)
{ try
{ X509Certificate2 cert = new X509Certificate2(@certificado,pin);
XadesService xadesService = new XadesService();
SignatureParameters parametros = new SignatureParameters();
parametros.SignaturePolicyInfo = new SignaturePolicyInfo();
parametros.SignaturePolicyInfo.PolicyIdentifier = "https://tribunet.hacienda.go.cr/docs/esquemas/2016/v4.1/Resolucion_Comprobantes_Electronicos_DGT-R-48-2016.pdf";
parametros.SignaturePolicyInfo.PolicyHash = "Ohixl6upD6av8N7pEvDABhEL6hM=";
parametros.SignaturePackaging = SignaturePackaging.ENVELOPED;
parametros.DataFormat = new DataFormat();
parametros.Signer = new FirmaXadesNet.Crypto.Signer(cert);
FileStream fs = new FileStream(pathXML, FileMode.Open);
FirmaXadesNet.Signature.SignatureDocument docFirmado = xadesService.Sign(fs, parametros);
docFirmado.Save(archivo_firmado);
fs.Close();
docFirmado = null;
}
catch (Exception ex)
{ _firma.WriteToFile("error xades" + ex.Message);
throw;
}
}
Error returned is:
Unable to cast object of type 'System.Security.Cryptography.RSACng' to type 'System.Security.Cryptography.RSACryptoServiceProvider'.
As mentioned above, if called as on OleObject, no error is returned. The result signed file is created. Even with .dll registered with regasm. With all Dlls copied on the same folder as the PB app.
I did not find a way to try to sign from pb Code, that might be another option. But have no idea of PB code to achieve it.
I can send the ddl source if needed and some test values for signing.
Best Regards
Alfredo Santibáñez