NCrypt API NCryptCreatePersistedKey fails when NCRYPT_MACHINE_KEY_FLAG flag is used

Sudheendra Subbarao 6 Reputation points
2022-04-18T06:48:09.543+00:00

We are trying to use NCrypt APIs to perform encrypt and decrypt of data.
We are using these APIs in C++ static library which is consumed by Winrt component which is eventually consumed by C# UWP app

UWP App --> WinRT COmponent --> C++ static lib

we are using the below APIs in the C++ static lib.
NCryptOpenStorageProvider - with MS_PLATFORM_CRYPTO_PROVIDER ( we need to use this with TPM only)
NCryptCreatePersistedKey - with NCRYPT_OVERWRITE_KEY_FLAG | NCRYPT_MACHINE_KEY_FLAG flags

if we use NCryptCreatePersistedKey with dwFlags as 0 (i.e current user) it works fine.
if we use NCryptCreatePersistedKey with dwFlags as NCRYPT_MACHINE_KEY_FLAG, the API fails.

It would be great if anyone can help with this

Universal Windows Platform (UWP)
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,071 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,912 questions
{count} votes