带有SID的ProtectKeysWithDpapiNG用于GMSA用户抛出异常

问题描述

您好,我们正在尝试使用DPAPI-NG编写.net核心控制台应用程序,该应用程序将提示运行它的用户传递base64string密钥,然后将其存储在设置文件中,供运行为GMSA进行加密。我正在尝试设置Dapi-NG,但它会抛出异常,并且似乎无法通过

var serviceCollection = new ServiceCollection();
        serviceCollection.AddDataProtection()
               .PersistKeysToFileSystem(new DirectoryInfo(directorylocation))
               .ProtectKeysWithDpapiNG(@"SID="+sid,flags: DpapiNGProtectionDescriptorFlags.None)
               .SetApplicationName(appName);

当我尝试使用IDataProtector保护方法时,出现以下异常:

未处理的异常:System.Security.Cryptography.CryptographicException:无法解密指定的数据。 在Microsoft.AspNetCore.Cryptography.UnsafeNativeMethods.ThrowExceptionForNCryptStatusImpl(Int32 ntstatus) 在Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.UnprotectWithDpapiNgcore(Byte * pbData,UInt32 cbData) 在Microsoft.AspNetCore.DataProtection.Cng.DpapiSecretSerializerHelper.UnprotectWithDpapiNG(Byte [] protectedData) 在Microsoft.AspNetCore.DataProtection.XmlEncryption.DpapiNGXmlDecryptor.Decrypt(XElement加密元素) 在Microsoft.AspNetCore.DataProtection.XmlEncryption.XmlEncryptionExtensions.DecryptElement(XElement元素,IActivator激活器) 在Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.IInternalXmlKeyManager.DeserializeDescriptorFromKeyElement(XElement keyElement) 在System.Lazy`1.ViaFactory(LazyThreadSafetyMode模式)下

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)