110,534
社区成员
发帖
与我相关
我的任务
分享
public static bool InstallCertificate(string certFilePath, string password, StoreLocation location, StoreName storeName)
{
try
{
if (!File.Exists(certFilePath))
{
SubDebug(string.Format("Certificate file not exist.\t{0}", certFilePath));
return false;
}
byte[] certData = File.ReadAllBytes(certFilePath);
X509Certificate2 cert = new X509Certificate2(certData, password,X509KeyStorageFlags.Exportable);
X509Store store = new X509Store(storeName, location);
store.Open(OpenFlags.MaxAllowed);
store.Remove(cert);
store.Add(cert);
store.Close();
SubDebug(string.Format("Certificate installed.\tCertificate file:{0}\tStore:{1}", certFilePath, storeName));
return true;
}
catch (Exception ex)
{
SubDebug(string.Format("Install certificate fail.\tCertificate file:{0}\t{1}\tStore:{1}", certFilePath, ex.Message));
return false;
}
}
SingleSite.Bindings.Add(string.Format("*:{0}:", port), byteCertHash, "MY");