1 year ago
#253857
Rholds
Problem trying to import PFX certificate in asp .NET Core
I'm creating a program with ASP .NET Core MVC, which signs PDFs with a digital signature. And I use a digital certificate PFX file created by windows powershell which should be loaded by the application and used to sign the PDF, but I can't load the PFX because of some privacy issue.
this is the problem that appears at the time of the bug:
An unhandled exception occurred while processing the request. WindowsCryptographicException: unspecified error Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(byte[] rawData, string fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags)
WindowsCryptographicException: unspecified error Internal.Cryptography.Pal.CertificatePal.FromBlobOrFile(byte[] rawData, string fileName, SafePasswordHandle password, X509KeyStorageFlags keyStorageFlags) System.Security.Cryptography.X509Certificates.X509Certificate..ctor(string fileName, string password, X509KeyStorageFlags keyStorageFlags) Spire.Pdf.Security.PdfCertificate..ctor(string pfxPath, string password)
what is this problem and how to solve it?
some additional information that might be useful, this PFX file was created on another computer and I emailed it to myself and downloaded it to my computer, because for some reason I can't use Windows powershell correctly to create the certificate on my own machine.
small part of code until the bug line:
public async Task<ActionResult> UploadFile(IFormFile file)
{
string nome = HttpContextAccessor.HttpContext.Session.GetString("NomeUsLog");
string path = "";
string filename ="Oxen" + Path.GetExtension(file.FileName);
path = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), "Upload"));
string pathUsuario = Path.Combine(path, nome);
if (file.Length > 0)
{
using (var filestream = new FileStream(Path.Combine(pathUsuario, filename), FileMode.Create))
{
await file.CopyToAsync(filestream);
}
//Create a PdfDocument object
PdfDocument doc = new PdfDocument();
//Load a sample PDF file
string filePath = Path.Combine(pathUsuario, filename);
doc.LoadFromFile(filePath);
//Load the certificate
//on this line the bug occurs
PdfCertificate cert = new PdfCertificate(pathUsuario, "CertificadoDig.pfx");
c#
certificate
digital-signature
x509certificate
pfx
0 Answers
Your Answer