당신은 인증서 저장소에서 인증서를 삭제하려면 닷넷 프레임 워크의 X509Store
와 releated 클래스를 시도 할 수 있습니다. 다음 코드 예제에서는 현재 사용자의 내 저장소에서 인증서를 삭제합니다
// Use other store locations if your certificate is not in the current user store.
X509Store store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadWrite | OpenFlags.IncludeArchived);
// You could also use a more specific find type such as X509FindType.FindByThumbprint
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, "yoursubjectname", false);
foreach (var cert in col)
{
Console.Out.WriteLine(cert.SubjectName.Name);
// Remove the certificate
store.Remove(cert);
}
store.Close();
BEGIN 편집 : 코드 샘플이를 제거하는 방법을 보여주는 내 대답을 업데이 트했습니다 코멘트 섹션에서 의견을 바탕으로 인증서와 체인의 모든 인증서 :
X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, "yoursubjectname", false);
X509Chain ch = new X509Chain();
ch.Build(col[0]);
X509Certificate2Collection allCertsInChain = new X509Certificate2Collection();
foreach (X509ChainElement el in ch.ChainElements)
{
allCertsInChain.Add(el.Certificate);
}
store.RemoveRange(allCertsInChain);
최종 편집
희망이 도움이됩니다.
는 그것이 체인 thoese를 포함하여 컴퓨터에서 모든 인증서를 제거합니다 있는지 확인 것인가? – daehaai
여기에 또 하나의 질문이 있습니다. 마법사를 사용하여 설치하는 경우 "유형에 따라 인증서 자동 저장"옵션이 있습니다. 이 코드로 부식 저장소에 cert를 어떻게 설치 하시겠습니까? – daehaai
@activebiz : 아니요, Remove() 함수는 인증서 체인의 인증서를 제거하지 않습니다. 체인에서 인증서를 삭제하는 방법을 보여주기 위해 샘플로 내 대답을 업데이트했습니다. – Hans