다른 서비스 공급 업체에서 배포 한 인증서 (.pem 파일)가 있습니다. 공급 업체의 인증서를 다운로드하여 로컬 드라이브에 저장했습니다. 내 WCF 클라이언트에서 로컬 드라이브에서이 인증서를로드하려고하는데 서비스와 통신 할 때 "개인 키가 X.509 인증서에 없습니다"라는 오류 메시지가 나타납니다. 이 오류를 해결하려면 로컬 인증서 저장소에이 인증서를로드해야한다고 들었습니다. 누구든지 방향을 제시 할 수 있습니까? 감사!다른 인증서를 로컬 인증서 저장소에로드하는 방법은 무엇입니까?
파일 매개 변수에 지정된 경로에서 인증서를로드하는 기능은 다음과 같습니다.
public static X509Certificate LoadCertificate(string file)
{
try
{
return X509Certificate.CreateFromCertFile(file);
}
catch (System.Security.Cryptography.CryptographicException)
{
string filestr = File.ReadAllText(file);
StringBuilder sb = new StringBuilder(filestr.Remove(0, filestr.IndexOf("-----BEGIN CERTIFICATE-----")));
sb.Replace("-----BEGIN CERTIFICATE-----", "");
sb.Replace("-----END CERTIFICATE-----", "");
//Decode
try
{ //see if the file is a valid Base64 encoded cert
byte[] certBytes = Convert.FromBase64String(sb.ToString());
return new X509Certificate(certBytes);
}
catch (System.FormatException)
{
throw;
}
}
}
내 WCF 클라이언트에서 LoadCertificate() 함수에서 만든 인증서를로드하고 있습니다.
public X509Certificate Certificate { get; set; }
ClientCredentials loginCredentials = new ClientCredentials();
loginCredentials.UserName.UserName = this.UserId;
loginCredentials.UserName.Password = this.Password;
loginCredentials.ClientCertificate.Certificate = new X509Certificate2(this.Certificate);
그냥 마우스 오른쪽 버튼으로 클릭하고 "설치"를 선택하십시오. – Yahia
몇 가지 코드를 공유 할 수 있습니까? 그렇지 않다면, @ Yahia의 해결책이 유일한 기회 일 수 있습니다. –
오른쪽 클릭시 "설치"옵션을 찾지 못했습니다. 또한 공급 업체의 지시 사항은 "이 인증서는 .pem 확장명으로 웹 서버에 파일로 저장해야합니다."입니다. 인증서를 설치해야하거나 저장해야한다는 의미인지 여부는 알 수 없습니다. – Jyina