2012-03-08 60 views
1

如何註冊在CNG用自己的密鑰團等格式的自定義密鑰存儲供應商?我真正想做的是提供一種在.NET中處理自定義CNG密鑰BLOB格式的功能。我已經閱讀過CNG文檔,它提供了添加第三方KSP的方法,但找不到任何示例或教程如何做到這一點。的Windows CNG自定義密鑰存儲提供

+0

哎wilkexx,你有沒有找到一個方法來做到這一點樣品KSP? – schmudu 2013-10-24 21:47:52

回答

1

如何使用自己的密鑰在CNG中註冊自定義密鑰存儲提供程序 BLOB格式等?

既然您只想註冊,我假設您已經準備好了自定義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); 
    } 
}