Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions NFe.Utils/Assinatura/Assinador.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@

documento.LoadXml(xml);

var docXml = new SignedXml(documento) { SigningKey = certificadoDigital.PrivateKey };
SignedXml docXml = new SignedXml(documento);

// Pega a chave RSA de forma "moderna", compatível com CNG e CSP
RSA rsa = certificadoDigital.GetRSAPrivateKey();

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 71 in NFe.Utils/Assinatura/Assinador.cs

View workflow job for this annotation

GitHub Actions / build (windows-2022)

The type or namespace name 'RSA' could not be found (are you missing a using directive or an assembly reference?)
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RSA type requires a using directive for System.Security.Cryptography. Add using System.Security.Cryptography; at the top of the file to resolve this type.

Copilot uses AI. Check for mistakes.
if (rsa == null)
throw new Exception("O certificado não possui chave privada RSA.");

docXml.SigningKey = rsa;
Comment on lines +71 to +75
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RSA object returned by GetRSAPrivateKey() should be disposed after use to avoid resource leaks. Since SignedXml may need the key for the entire lifetime of the object, consider storing the RSA instance and disposing it in the finally block, or document that the caller is responsible for the lifecycle management of the certificate which owns the RSA key.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +75
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new RSA key retrieval logic lacks test coverage. Consider adding tests to verify:

  1. Successful RSA key retrieval from a certificate
  2. The exception thrown when a certificate doesn't have an RSA private key
  3. Compatibility with both CNG and CSP providers

Note: The NFe.Utils.Testes directory exists but currently has no tests for the Assinador class.

Copilot uses AI. Check for mistakes.

docXml.SignedInfo.SignatureMethod = signatureMethod;

Expand Down Expand Up @@ -103,4 +110,4 @@

}
}
}
}
Loading