.net - Windows CNG 自定义 key 存储提供程序

标签 .net windows cryptography cryptoapi cng

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

最佳答案

How to register a custom key storage provider in CNG with its own key BLOB format, etc?

由于您只想注册,我假设您已经准备好自定义 KSP,只需注册即可。无论如何,您可以通过编程来完成。

以下代码来自加密提供程序开发套件提供的示例 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);
    }
}

关于.net - Windows CNG 自定义 key 存储提供程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9626883/

相关文章:

c# - 为同一个匿名方法创建两个委托(delegate)实例不相等

c# - 任务报告 IsCompleted 但仍然阻止结果?

python - 使用 tkinter 获取命令窗口输出以显示在小部件中

python - 错误: Could not find a version that satisfies the requirement azure-functions

java - 我应该如何生成初始化 vector ?

.net - 将 Dotfuscator 作为构建后事件运行

c# - 如何限制表达式访问 Roslyn 中的外部类型?

windows - Windows 中 OS X VM 上的 MonoTouch?

java - DES 蛮力(学术)

encryption - HashiCorp Vault项目-编写其他键/值对而不覆盖现有键/值对