我想尝试使用Win32_EncryptableVolume类的加密方法加密包含操作系统安装的逻辑磁盘卷。在使用此方法之前,我必须创建一个密钥来保护此卷,为此我有几个选项,但如果我想加密包含操作系统安装的逻辑磁盘卷,我必须使用{{3方法。
当我尝试调用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);
}
答案 0 :(得分:1)
在您提问的评论中,即使您没有传递任何值,必须明确声明inParams
。
ManagementBaseObject inParams;
inParams = PrivateLateBoundObject.GetMethodParameters("ProtectKeyWithTPM");
要获得Win32_EncryptableVolume
课程的完整映射,请查看https://github.com/Internet2/incert/blob/baf2ab60299df1dcd93192da7600342dda2497ad/Windows/Engine/NativeCode/Wmi/EncryptableVolume.cs