Hi,
Is Spire.Pdf support to add digital signatrue/certificate in pdf using .pem file instead of .pfx file? I am using freespire.pdf(8.6.0) in .NetCore -6
While i am trying to execute below code it working fine locally
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(signedDocPath);
X509Certificate2 pemCertificate = X509Certificate2.CreateFromPemFile(certificatePath); -> certificate path is .pem file attached
Logger.Info("X509Certificate2 fetched");
PdfCertificate cert = new PdfCertificate(pemCertificate); //, GoatSignConsts.GoatSignCertificatePassword);
Logger.Info("Digital certificate fetched from fetched");
PdfSignature signature = new PdfSignature(doc, doc.Pages[doc.Pages.Count - 1], cert, "GoatSign Digital Signature");
Logger.Info("signature imported");
//Set the document permission to forbid changes but allow form fill
signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges | PdfCertificationFlags.AllowFormFill;
doc.SaveToFile(finalDocument);
but when it gives below error on production
ERROR 2023-06-06 15:21:26,529 [8 ] spNetCore.Antiforgery.DefaultAntiforgery - An exception was thrown while deserializing the token.
Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery token could not be decrypted.
---> System.Security.Cryptography.CryptographicException: The key {975adf25-83ab-4cf2-a684-bf213ff4a01c} was not found in the key ring.
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.UnprotectCore(Byte[] protectedData, Boolean allowOperationsOnRevokedKeys, UnprotectStatus& status)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.DangerousUnprotect(Byte[] protectedData, Boolean ignoreRevocationErrors, Boolean& requiresMigration, Boolean& wasRevoked)
at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Unprotect(Byte[] protectedData)
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgeryTokenSerializer.Deserialize(String serializedToken)
at Microsoft.AspNetCore.Antiforgery.DefaultAntiforgery.GetCookieTokenDoesNotThrow(HttpContext httpContext)
WARN 2023-06-06 15:21:54,761 [18 ] Microsoft.EntityFrameworkCore.Query - Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'
WARN 2023-06-06 15:22:03,201 [8 ] Microsoft.EntityFrameworkCore.Query - Compiling a query which loads related collections for more than one collection navigation either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default Entity Framework will use 'QuerySplittingBehavior.SingleQuery' which can potentially result in slow query performance. See https://go.microsoft.com/fwlink/?linkid=2134277 for more information. To identify the query that's triggering this warning call 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'
ERROR 2023-06-06 15:22:07,764 [6 ] n.Web.Controllers.SignDocumentController - Digital Certificate Error :
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: The system cannot find the file specified.
at System.Security.Cryptography.CngKeyLite.ImportKeyBlob(String blobType, ReadOnlySpan`1 keyBlob, Boolean encrypted, ReadOnlySpan`1 password)
at System.Security.Cryptography.CngPkcs8.ImportPkcs8(ReadOnlySpan`1 keyBlob)
at System.Security.Cryptography.CngPkcs8.ImportPkcs8PrivateKey(ReadOnlySpan`1 source, Int32& bytesRead)
at System.Security.Cryptography.RSAImplementation.RSACng.ImportPkcs8PrivateKey(ReadOnlySpan`1 source, Int32& bytesRead)
at Internal.Cryptography.PemKeyImportHelpers.ImportPem(ReadOnlySpan`1 input, FindImportActionFunc callback)
at System.Security.Cryptography.RSA.ImportFromPem(ReadOnlySpan`1 input)
at System.Security.Cryptography.X509Certificates.X509Certificate2.ExtractKeyFromPem[TAlg](ReadOnlySpan`1 keyPem, String[] labels, Func`1 factory, Func`2 import)
at System.Security.Cryptography.X509Certificates.X509Certificate2.CreateFromPem(ReadOnlySpan`1 certPem, ReadOnlySpan`1 keyPem)
at System.Security.Cryptography.X509Certificates.X509Certificate2.CreateFromPemFile(String certPemFilePath, String keyPemFilePath)
at GoatSign.Web.Controllers.SignDocumentController.AddDigitalSignatureToSigedDocument(String signedDocPath, Guid sReqId, String documentName)
Please guid us
Thanks