public ActionResult DownloadPublic(String thumbprint) { Console.WriteLine("GET /api/leaf/download/" + thumbprint + "/public"); String pathAndFilename = Path.Combine(CAStorePathInfo.LeafCertPath, $"{thumbprint}.pfx"); if (System.IO.File.Exists(pathAndFilename)) { Response.Headers["Content-Disposition"] = new ContentDispositionHeaderValue("attachment") { FileName = $"{thumbprint}.pub" }.ToString(); CertificateAndPems result = new CertificateAndPems(new X509Certificate2(pathAndFilename, null, X509KeyStorageFlags.Exportable)); Byte[] fileContents = Encoding.UTF8.GetBytes(result.PublicKeyPem); return(new FileContentResult(fileContents, new MediaTypeHeaderValue("application/octet-stream"))); } else { return(NotFound()); } }
public ActionResult DownloadPrivate() { Console.WriteLine("GET /api/ca/download/private"); String pathAndFilename = CAStorePathInfo.CACertPathAndFileName; if (System.IO.File.Exists(pathAndFilename)) { Response.Headers["Content-Disposition"] = new ContentDispositionHeaderValue("attachment") { FileName = $"ca.key" }.ToString(); CertificateAndPems result = new CertificateAndPems(new X509Certificate2(pathAndFilename, null, X509KeyStorageFlags.Exportable)); Byte[] fileContents = Encoding.UTF8.GetBytes(result.PrivateKeyPem); return(new FileContentResult(fileContents, new MediaTypeHeaderValue("application/octet-stream"))); } else { return(NotFound()); } }