문제

인증서 요청/수락 프로세스 중에 인증서 친화적 이름을 설정하려고합니다. 나는 이것이 인증서보다는 Microsoft Store의 속성과 그것을 설정하는 데 사용될 수있는 .NET/C# 기술이 궁금하다는 것을 이해합니다.

도움이 되었습니까?

해결책 2

그래서 다음은이 작업을 수행하는 방법에 대한 Commmand 라인 예입니다. Cryptoapi를 감싸는 Microsoft의 Capicom이 필요합니다.

친숙한 이름은 인증서 대신 CERT 스토어의 속성 이므로이 코드는 CERT 스토어로 인증서를 가져오고 친숙한 이름을 설정합니다.

코드는 두 개의 매개 변수를 사용하여 CERT 파일의 경로와 설정하려는 친숙한 이름을 사용합니다.

암호:-

using System;

using System.Collections.Generic;

using System.Text;

using CAPICOM;

using System.Collections;

using System.Runtime.InteropServices;


namespace CertTool

{

    class Program
    {
        const uint CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x20000;
        const int CAPICOM_PROPID_FRIENDLY_NAME = 11;
        const int CAPICOM_ENCODE_BINARY = 1;

        static private String _currStoreName = "My";
        static private String _FriendlyName = "Not Set";
        static private String _CertPath = "C:\\test.cer";
        static StoreClass _oCurrStore;
        static ExtendedPropertyClass _friendlyProp;
        static CertificateClass _certificate;
        static ExtendedProperties _extendedProp;

        static void Main(string[] args)
        {
            try
            {
                //Friendly name Argument
                if (args.Length > 0)
                {
                    _FriendlyName = args[0];
                }
                //Certpath argument
                if (args.Length > 1) 
                {
                    _CertPath = args[1];
                }
                //Set and open the Store
                _oCurrStore = new StoreClass();
                _oCurrStore.Open(
                    CAPICOM_STORE_LOCATION.CAPICOM_LOCAL_MACHINE_STORE,
                    _currStoreName,
                    CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_EXISTING_ONLY |
                    CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED);
                //Call the import certificate function
                importCert();
            }
            catch(Exception ex){
                Console.WriteLine(ex.Message);
                Console.WriteLine(args[0]);
            }
        }
        //Function import the certificate to the machine store and sets the friendly name
        static bool importCert()
        {
            try
            {
                //Create Certificate Object
                _certificate = new CertificateClass();
                //Load the certificate into the obejct from file
                _certificate.Load(_CertPath, "", CAPICOM_KEY_STORAGE_FLAG.CAPICOM_KEY_STORAGE_EXPORTABLE, CAPICOM_KEY_LOCATION.CAPICOM_LOCAL_MACHINE_KEY);
                //Create extended property Class for friendly name
                _friendlyProp = new ExtendedPropertyClass();
                _friendlyProp.PropID =  CAPICOM_PROPID.CAPICOM_PROPID_FRIENDLY_NAME;
                _friendlyProp.set_Value(CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BINARY, _FriendlyName);

                //Add extendedProp on cert object
                _extendedProp = _certificate.ExtendedProperties();
                //Set extendded prop to friendly name object
                _extendedProp.Add(_friendlyProp);
                _oCurrStore.Add(_certificate);
                return true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(_CertPath);
                return true;
            }
        }
    }
}

다른 팁

x509certificate2.frierdlyname을 사용하십시오. 그러나 인증서를 PFX/PKCS#12로 내보내야합니다.

X509Certificate2 certificate = new X509Certificate2(...);
certificate.FriendlyName = "MyName";
File.WriteAllBytes(path, certificate.Export(X509ContentType.Pkcs12));

좋아, 여기에 대한 답을 찾았습니다.

안녕,

필요에 맞는 지 확인하려면 이것을 살펴보십시오.

X64 환경에서 .NET 코드를 실행하면 다음 오류 메시지가 표시됩니다.

"실패 -CLSID의 구성 요소를 위해 COM 클래스 공장을 다시 비롯해 ...."

예 : CMS 내보내기 / 가져 오기 서버 측 .NET 코드 = "ExportSiteContentIncremental (...) 실패-CLSID {CA0752B3-021C-4F99-82E3-2C0F19C5E953}가있는 구성 요소에 대한 COM 클래스 팩토리를 재조정하여 다음 오류로 인해 실패했습니다 : 80040154."

해결 방법 :

가능한 해결 방법은 프로젝트의 플랫폼을 '모든 CPU'에서 'x86'으로 수정하는 것입니다 (프로젝트 속성, 빌드/플랫폼의 대상)

rootcause

VSS Interop은 32 비트 프레임 워크를 사용하는 관리 조립품이며 DLL에는 32 비트 COM 객체가 포함되어 있습니다. 64 비트 환경 에서이 COM DLL을 실행하면 오류 메시지가 표시됩니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top