2012-03-08 5 views
1

カスタムキーストレージプロバイダを独自のキーBLOB形式などでCNGに登録するにはどうすればよいですか?私が本当にやりたいことは、.NETでカスタムCNGキーBLOB形式を処理する機能を提供することです。私は、サードパーティのKSPを追加する方法を提供していますが、どのようなサンプルやチュートリアルを見つけることができないというCNGドキュメントを読みました。Windows CNGカスタムキーストレージプロバイダ

+0

に付属のサンプルKSPからであるwilkexxねえ、あなたはこれを行う方法を見つけましたか? – schmudu

答えて

1

カスタムキーストレージプロバイダを独自のキー BLOB形式などでCNGに登録するにはどうすればよいですか?

あなたが登録したいだけなので、私はあなたがすでにカスタムKSPを準備していると仮定しているので、登録する必要があります。とにかく、あなたはプログラム的にそれをすることができます。

次のコードは、暗号化プロバイダ開発キット (http://www.microsoft.com/en-us/download/details.aspx?id=30688

void 
RegisterProvider(
    void 
    ) 
{ 
    NTSTATUS ntStatus = STATUS_SUCCESS; 

    // 
    // Make CNG aware that our provider 
    // exists... 
    // 
    ntStatus = BCryptRegisterProvider(
        SAMPLEKSP_PROVIDER_NAME, 
        0,       // Flags: fail if provider is already registered 
        &SampleKSPProvider 
        ); 
    if (!NT_SUCCESS(ntStatus)) 
    { 
     wprintf(L"BCryptRegisterProvider failed with error code 0x%08x\n", ntStatus); 
    } 

    // 
    // Add the algorithm name to the priority list of the 
    // symmetric cipher algorithm class. (This makes it 
    // visible to BCryptResolveProviders.) 
    // 
    ntStatus = BCryptAddContextFunction(
        CRYPT_LOCAL,     // Scope: local machine only 
        NULL,       // Application context: default 
        NCRYPT_KEY_STORAGE_INTERFACE, // Algorithm class 
        NCRYPT_KEY_STORAGE_ALGORITHM, // Algorithm name 
        CRYPT_PRIORITY_BOTTOM   // Lowest priority 
        ); 
    if (!NT_SUCCESS(ntStatus)) 
    { 
     wprintf(L"BCryptAddContextFunction failed with error code 0x%08x\n", ntStatus); 
    } 

    // 
    // Identify our new provider as someone who exposes 
    // an implementation of the new algorithm. 
    // 
    ntStatus = BCryptAddContextFunctionProvider(
        CRYPT_LOCAL,     // Scope: local machine only 
        NULL,       // Application context: default 
        NCRYPT_KEY_STORAGE_INTERFACE, // Algorithm class 
        NCRYPT_KEY_STORAGE_ALGORITHM, // Algorithm name 
        SAMPLEKSP_PROVIDER_NAME,  // Provider name 
        CRYPT_PRIORITY_BOTTOM   // Lowest priority 
        ); 
    if (!NT_SUCCESS(ntStatus)) 
    { 
     wprintf(L"BCryptAddContextFunctionProvider failed with error code 0x%08x\n", ntStatus); 
    } 
} 
関連する問題