When using the .NET 8 SDK in a Windows environment, everything works as expected. However, when the same application is published and deployed to a Linux environment, an issue occurs during the signing and reporting of simplified XML invoices.
Error Message Returned by SDK:
[Error] Parsing EInvoice Certificate
[Error] Populating Signed Signature Properties
Root Cause:
After investigation, the issue seems to originate from the ParseCertificateMiddleware
class. Specifically, the following code:
X509Certificate2 X509Certificate2 = new X509Certificate2(
(byte[])(object)(from x in Encoding.UTF8.GetBytes(eInvoiceData.CertificateContent)
select (sbyte)x).ToArray());
This works on Windows but fails on Linux due to differences in how certificate content is handled. It appears that the certificate content is base64-encoded, and decoding it with Encoding.UTF8.GetBytes
leads to an invalid byte array on Linux.
Suggested Fix:
Changing the code to use proper base64 decoding instead resolves the issue across both environments:
X509Certificate2 X509Certificate2 = new X509Certificate2(
(byte[])(object)(from x in Convert.FromBase64String(eInvoiceData.CertificateContent)
select (sbyte)x).ToArray());
This approach correctly handles the certificate bytes and resolves the signing and validation issues when deployed on Linux.
Request:
Kindly review and consider updating the SDK to ensure platform-independent handling of certificates. This will help avoid deployment issues in Linux-based environments.