在 Windows 7 Pro x64 上,我尝试使用 Cryptography API Next Generation 创建一个持久的 AES 密钥。
问题是 NCryptCreatePersistedKey 函数返回 NTE_NOT_SUPPORTED。
我的代码:
#include "Windows.h"
#include "bcrypt.h"
#include "ncrypt.h"
int main() {
NCRYPT_PROV_HANDLE hProvider;
NCRYPT_KEY_HANDLE hKey;
// Open storage provider
HRESULT status = NCryptOpenStorageProvider(&hProvider,
MS_KEY_STORAGE_PROVIDER, 0);
// Get stored cipher key
status = NCryptOpenKey(hProvider, &hKey, L"test-key", 0, 0);
// Create key if it doesn't exist
if (status == NTE_BAD_KEYSET) {
status = NCryptCreatePersistedKey(hProvider, &hKey,
BCRYPT_AES_ALGORITHM, L"test-key", 0, 0);
status = NCryptFinalizeKey(hKey, 0);
}
return 0;
}
这适用于 Windows 10 Pro x64。
并且文档说最低支持的客户端是 Windows Vista ......
谢谢你的帮助。