Win32_EncryptableVolume类的ProtectKeyWithTPM方法导致异常
本文关键字:异常 方法 ProtectKeyWithTPM EncryptableVolume 类的 Win32 | 更新日期: 2023-09-27 18:16:02
我想尝试使用Win32_EncryptableVolume类的加密方法加密包含操作系统安装的逻辑磁盘卷。在我使用这种方法之前,我必须创建一个密钥来保护这个卷,为此我有几个选项,但如果我想加密包含操作系统安装的逻辑磁盘卷,我必须使用ProtectKeyWithTPM方法。
当我尝试调用ProtectKeyWithTPM
方法时发生问题,它返回给我以下堆栈跟踪:
System.Runtime.InteropServices.COMException (0x800706BE)
em System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
em System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
em ListDrivers.BitLocker.callMethod(String method, ManagementObject privateLateBoundObject, ManagementBaseObject inParams) na C:'Users'admin'documents'visual studio 2015'Projects'BitlockerTeste'BitlockerTeste'BitLocker.cs:linha 221
em ListDrivers.BitLocker.defineTPM(String id, ArrayList drivers) na C:'Users'admin'documents'visual studio 2015'Projects'BitlockerTeste'BitlockerTeste'BitLocker.cs:linha 149
em ListDrivers.Program.<TPMProtection>d__8.MoveNext() na C:'Users'admin'documents'visual studio 2015'Projects'BitlockerTeste'BitlockerTeste'Program.cs:linha 275
--- Fim do rastreamento de pilha do local anterior onde a exceção foi gerada ---
em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
em System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
em ListDrivers.Program.<encryptMenu>d__7.MoveNext() na C:'Users'admin'documents'visual studio 2015'Projects'BitlockerTeste'BitlockerTeste'Program.cs:linha 241
这个错误只发生在这个方法上,所有其他Win32_EncryptableVolume
方法正常工作,我已经在许多网站上搜索了这个解决方案,但我没有找到任何帮助。
我的问题是,当我试图用TPM保护卷时,为什么会发生这种情况?为什么其他不使用TPM的保护方法都能正常工作?
编辑: defineTPM
方法:
public static UInt32 defineTPM(string id, ArrayList drivers)
{
String deviceId = findByDriverLetter(id, drivers);
if (deviceId != null)
{
ManagementObject privateLateBoundObject = returnManagementObjectForDevice(deviceId);
ManagementBaseObject inParams = null;
return callMethod("ProtectKeyWithTPMandStartupKey", privateLateBoundObject, inParams);
}
return Convert.ToUInt32(2147942487);
}
callMethod
方法:
private static UInt32 callMethod(String method, ManagementObject privateLateBoundObject, ManagementBaseObject inParams)
{
ManagementBaseObject outParams = privateLateBoundObject.InvokeMethod(method, inParams, null);
return Convert.ToUInt32(outParams.Properties["ReturnValue"].Value);
}
正如您的问题的评论所建议的,您必须显式声明inParams
,即使您不传递任何值。
ManagementBaseObject inParams;
inParams = PrivateLateBoundObject.GetMethodParameters("ProtectKeyWithTPM");
有关Win32_EncryptableVolume
类的完整映射,请查看https://github.com/Internet2/incert/blob/baf2ab60299df1dcd93192da7600342dda2497ad/Windows/Engine/NativeCode/Wmi/EncryptableVolume.cs