0

我想尝试使用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);
}
4

1 回答 1

1

正如您问题的评论中所建议的那样,您必须明确声明inParams,即使您没有传递任何值。

ManagementBaseObject inParams;
inParams = PrivateLateBoundObject.GetMethodParameters("ProtectKeyWithTPM");

有关Win32_EncryptableVolume类的完整映射,请查看https://github.com/Internet2/incert/blob/baf2ab60299df1dcd93192da7600342dda2497ad/Windows/Engine/NativeCode/Wmi/EncryptableVolume.cs

于 2016-11-04T16:42:21.753 回答