我正在尝试使用 DPAPI-NG 加密数据,但在执行NCryptProtectSecret时失败,它返回:
0x80090034 (NTE_ENCRYPTION_FAILURE)
我用本地用户 SID创建了NCryptCreateProtectionDescriptor :
"SID=S-1-5-21-2942599413-360359348-3087651068-500"
然后我使用这个描述符实例作为NCryptProtectSecret的输入,但它不起作用。
如果我使用以下保护描述符:
"LOCAL=user"
一切似乎都很好,但它不适用于用户或组的 SID。我已经在 Windows Server 2012R2 和 Windows Server 2016 上对此进行了测试。
任何想法?
这是一个代码示例:
SECURITY_STATUS Status;
PBYTE ProtectedData = NULL;
ULONG ProtectedDataLength = 0;
NCRYPT_DESCRIPTOR_HANDLE DescriptorHandle = NULL;
LPCWSTR ProtectionDescString = L"SID=S-1-5-21-2942599413-360359348-3087651068-500";
Status = NCryptCreateProtectionDescriptor(
ProtectionDescString,
0,
&DescriptorHandle
);
// Status is ERROR_SUCCESS (zero)
LPCWSTR SecretString = L"Some message to protect";
PBYTE Secret = (PBYTE)SecretString;
DWORD SecretLength = (ULONG)( (wcslen(SecretString)+1)*sizeof(WCHAR) );
Status = NCryptProtectSecret(
DescriptorHandle,
0,
PlainText,
PlainTextLength,
NULL, // Use default allocations by LocalAlloc/LocalFree
NULL, // Use default parent windows handle.
&ProtectedData, // out LocalFree
&ProtectedDataLength
);
**// Status == NTE_ENCRYPTION_FAILURE**