1
0
mirror of synced 2024-11-27 23:50:49 +01:00

Save cert to disk

This commit is contained in:
Yuchen Ji 2022-04-07 00:05:31 +08:00
parent 3129170217
commit 1d211d5f15
4 changed files with 12 additions and 1 deletions

View File

@ -100,7 +100,8 @@ internal class Program
var paths = $"Paths: {nameof(PathHelper.HtmlRootPath)}: {PathHelper.HtmlRootPath}\n" +
$"{nameof(PathHelper.LogRootPath)}: {PathHelper.LogRootPath}\n" +
$"{nameof(PathHelper.DataBaseRootPath)}: {PathHelper.DataBaseRootPath}\n" +
$"{nameof(PathHelper.ConfigFilePath)}: {PathHelper.ConfigFilePath}\n";
$"{nameof(PathHelper.ConfigFilePath)}: {PathHelper.ConfigFilePath}\n" +
$"{nameof(PathHelper.CertRootPath)}: {PathHelper.CertRootPath}\n";
paths.Info();
}

View File

@ -129,10 +129,16 @@ public static class CertificateHelper
var certWithPrivateKey = new X509Certificate2(certPfxBytes, (string)null!,
X509_KEY_STORAGE_FLAGS_MACHINE);
AddCertToStore(rootCaWithPrivateKey, StoreName.My, StoreLocation.LocalMachine);
AddCertToStore(rootCaWithPrivateKey, StoreName.Root, StoreLocation.LocalMachine);
AddCertToStore(certWithPrivateKey, StoreName.My, StoreLocation.LocalMachine);
Directory.CreateDirectory(PathHelper.CertRootPath);
File.WriteAllBytes(Path.Combine(PathHelper.CertRootPath, "root.pfx"), rootCaWithPrivateKey.Export(X509ContentType.Pfx));
File.WriteAllBytes(Path.Combine(PathHelper.CertRootPath, "cert.pfx"), certWithPrivateKey.Export(X509ContentType.Pfx));
return certWithPrivateKey;
}

View File

@ -16,6 +16,8 @@ public static class Configs
public const string LOG_FOLDER = "log";
public const string CERT_FOLDER = "certs";
public const string LOG_BASE_NAME = "log";
public const string STATIC_FOLDER = "static";

View File

@ -17,6 +17,8 @@ public static class PathHelper
public static string LogRootPath => Path.Combine(BasePath, Configs.LOG_FOLDER);
public static string CertRootPath => Path.Combine(BasePath, Configs.CERT_FOLDER);
public static string ConfigFilePath => Environment.ProcessPath ?? string.Empty;
private static string BasePath