On Windows 7 Pro x64, I try to create a persistent AES key with Cryptography API Next Generation.
The problem is that the NCryptCreatePersistedKey function returns NTE_NOT_SUPPORTED.
My code:
#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;
}
That works on Windows 10 Pro x64.
And documentation says that minimum supported client is Windows Vista...
Thanks for your help.