Latest release (March 2025)
The release of GroupDocs.Signature version 25.3 adds new features and fixes.
Full list of changes in this release
Key | Category | Summary |
---|---|---|
SIGNATURENET-5163 | 🔧 Fix | PIN box for smart card authentication appears two times while signing PDF document |
SIGNATURENET-5208 | ★ Feature | Sign a PDF with custom hash signing function |
Major Features
Sign a PDF with custom hash signing function
🌐 This release introduces the ability to sign PDFs with a custom hash signing function, enabling digital signing with an external certificate. Developers can now implement their own digital signer by assigning a custom implementation to the CustomSignHash property in the signing options. This flexibility allows enforcement of specific cryptographic standards and security policies while also supporting different hash algorithms, so users can choose the algorithm that best fits their security needs. The provided sample demonstrates signing with a PFX certificate using SHA-256, ensuring robust document integrity and a verifiable digital signature.
public void SignDocument()
{
string certFilePath = "cert.pfx";
string sampleFilePath = "sample.pdf";
string sampleOutputFilePath = "signed.pdf";
using (Signature.Signature signature = new Signature.Signature(sampleFilePath))
{
// initialize digital option with certificate file path
DigitalSignOptions options = new DigitalSignOptions(certFilePath)
{
// certificate password
Password = "1234567890",
// digital certificate details
Reason = "Sign",
Contact = "JohnSmith",
Location = "Office1",
AllPages = true,
Width = 80,
Height = 60,
VerticalAlignment = VerticalAlignment.Bottom,
HorizontalAlignment = HorizontalAlignment.Right,
Margin = new Padding() { Bottom = 10, Right = 10},
HashAlgorithm = HashAlgorithm.Sha256
};
options.CustomSignHash = new CustomDigitalSigner();
signature.Sign(sampleOutputFilePath, options);
}
}
public class CustomDigitalSigner : ICustomSignHash
{
public byte[] CustomSignHash(byte[] signableHash, HashAlgorithm hashAlgorithm, SignatureContext signatureContext)
{
string inputP12 = "";
var inputPfxPassword = "1234567890";
X509Certificate2 signerCert = new X509Certificate2(inputP12, inputPfxPassword, X509KeyStorageFlags.Exportable);
RSACryptoServiceProvider rsaCSP = new RSACryptoServiceProvider();
var xmlString = signerCert.PrivateKey.ToXmlString(true);
rsaCSP.FromXmlString(xmlString);
byte[] signedData = rsaCSP.SignData(signableHash, hashAlgorithm);
return signedData;
}
}
PIN box for smart card authentication appears two times while signing PDF document
When signing a PDF with a smart card, the PIN entry prompt previously appeared twice due to redundant authentication requests. To resolve this, we added an internal validation mechanism that prevents multiple PIN prompts during the signing process. This improvement is seamlessly integrated and does not require any user action. It is available only when using a custom hash signing function, ensuring a smoother and more secure signing experience.