首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows CNG自定义密钥存储提供程序

Windows CNG自定义密钥存储提供程序
EN

Stack Overflow用户
提问于 2012-03-08 23:47:57
回答 1查看 3.3K关注 0票数 2

如何用自己的密钥BLOB格式以CNG注册自定义密钥存储提供者,等等?我真正想做的是提供一种在.NET中处理自定义CNG密钥BLOB格式的能力,我在CNG文档中看到它提供了一种添加第三方KSPs的方法,但是找不到任何示例或教程。

EN

回答 1

Stack Overflow用户

发布于 2015-01-16 11:03:25

如何用自己的密钥BLOB格式注册自定义密钥存储提供者?

既然你只想注册,我假设你已经准备好了定制的KSP,只需要注册它。不管怎么说,你可以用编程来做。

以下代码来自加密提供程序开发工具包(http://www.microsoft.com/en-us/download/details.aspx?id=30688)提供的示例KSP

代码语言:javascript
复制
    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);
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9626883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档