public static Exception LockDataVolume(ManagementObject encryptableVolume, out int returnValueLock)
        {
            ManagementBaseObject outParams = null;
            int       returnValue          = -1;
            Exception ex = Util.HandleExceptions(delegate
            {
                string deviceId = BitlockerUtil.GetDeviceId(encryptableVolume);
                Exception ex2;
                if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2))
                {
                    if (ex2 != null)
                    {
                        throw new VolumeLockedFindException(deviceId, ex2.Message, ex2);
                    }
                }
                else
                {
                    returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "Lock", null, null, out outParams);
                    if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2) && ex2 != null)
                    {
                        throw new VolumeLockedFindException(deviceId, ex2.Message, ex2);
                    }
                }
            });

            returnValueLock = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueLock, "LockDataVolume", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueLock, "LockDataVolume", ex));
        }
        public static List <string> GetLockedVolumes(out Exception ex)
        {
            List <string> lockedVolumes = null;

            ex = Util.HandleExceptions(delegate
            {
                ManagementObjectCollection encryptableVolumes = BitlockerUtil.GetEncryptableVolumes();
                if (encryptableVolumes != null)
                {
                    foreach (ManagementBaseObject managementBaseObject in encryptableVolumes)
                    {
                        ManagementObject managementObject = (ManagementObject)managementBaseObject;
                        string item = managementObject.GetPropertyValue("DeviceId").ToString();
                        Exception ex2;
                        bool flag = BitlockerLockUtil.IsVolumeLocked(managementObject, out ex2);
                        Util.ThrowIfNotNull(ex2);
                        if (flag)
                        {
                            if (lockedVolumes == null)
                            {
                                lockedVolumes = new List <string>();
                            }
                            lockedVolumes.Add(item);
                        }
                    }
                }
            });
            return(lockedVolumes);
        }
        public static Exception UnlockWithNumericalPassword(ManagementObject encryptableVolume, string numericalPassword, out int returnValueUnlockWithNumericalPassword)
        {
            ManagementBaseObject outParams = null;
            int       returnValue          = -1;
            Exception ex = Util.HandleExceptions(delegate
            {
                string deviceId = BitlockerUtil.GetDeviceId(encryptableVolume);
                Exception ex2;
                if (!BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex2))
                {
                    returnValue = 0;
                    throw new VolumeLockedFindException(deviceId, ex2.Message, ex2);
                }
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "UnlockWithNumericalPassword", new string[]
                {
                    "NumericalPassword"
                }, new object[]
                {
                    numericalPassword
                }, out outParams);
            });

            returnValueUnlockWithNumericalPassword = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueUnlockWithNumericalPassword, "UnlockWithNumericalPassword", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueUnlockWithNumericalPassword, "UnlockWithNumericalPassword", ex));
        }
示例#4
0
        public static Exception Resume(ManagementObject encryptableVolume, out int returnValueResume)
        {
            Exception ex          = null;
            int       returnValue = -1;

            returnValueResume = -1;
            if (encryptableVolume == null)
            {
                return(new EncryptableVolumeArgNullException("Resume"));
            }
            string volume = encryptableVolume.GetPropertyValue("DeviceId").ToString();

            if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex))
            {
                ex = new VolumeLockedException(volume);
                return(ex);
            }
            ex = Util.HandleExceptions(delegate
            {
                ManagementBaseObject managementBaseObject = null;
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "ResumeConversion", null, null, out managementBaseObject);
            });
            returnValueResume = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueResume, "Resume", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueResume, "Resume", ex));
        }
示例#5
0
        public static Exception AddNumericalPassword(ManagementObject encryptableVolume, string numericalPassword, out int returnValueNumericalPassword)
        {
            Exception ex = null;

            if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex))
            {
                returnValueNumericalPassword = 0;
                return(ex);
            }
            int returnValue = -1;
            ManagementBaseObject outParams = null;

            ex = Util.HandleExceptions(delegate
            {
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "ProtectKeyWithNumericalPassword", new string[]
                {
                    "FriendlyName",
                    "NumericalPassword"
                }, new object[]
                {
                    "FriendlyName",
                    numericalPassword
                }, out outParams);
            });
            returnValueNumericalPassword = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueNumericalPassword, "AddNumericalPassword", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueNumericalPassword, "AddNumericalPassword", ex));
        }
示例#6
0
        public static bool IsFilePathOnLockedVolume(string filePath, out Exception ex)
        {
            ex = null;
            List <string> lockedVolumes = BitlockerLockUtil.GetLockedVolumes(out ex);

            if (ex != null)
            {
                ex = new LockedVolumesFindException(ex.Message, ex);
                return(false);
            }
            if (lockedVolumes == null || lockedVolumes.Count == 0)
            {
                return(false);
            }
            Dictionary <string, string> mountPointVolumeIDMappings = BitlockerUtil.GetMountPointVolumeIDMappings(out ex);

            if (mountPointVolumeIDMappings == null)
            {
                ex = new MountPointsFindException(ex.Message, ex);
                return(false);
            }
            bool flag = false;

            foreach (string text in mountPointVolumeIDMappings.Keys)
            {
                if (filePath.StartsWith(text))
                {
                    flag = true;
                    if (lockedVolumes.Contains(mountPointVolumeIDMappings[text]))
                    {
                        return(true);
                    }
                }
            }
            if (!flag)
            {
                ex = new InvalidFilePathException(filePath);
            }
            return(false);
        }
示例#7
0
        public static Exception Encrypt(ManagementObject encryptableVolume, bool usedOnly, out int returnValueEncrypt)
        {
            Exception ex          = null;
            int       returnValue = -1;

            if (BitlockerLockUtil.IsVolumeLocked(encryptableVolume, out ex))
            {
                returnValueEncrypt = 0;
                return(ex);
            }
            ex = Util.HandleExceptions(delegate
            {
                ManagementBaseObject managementBaseObject = null;
                if (Util.IsOperatingSystemWin8OrHigher() && usedOnly)
                {
                    returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "Encrypt", new string[]
                    {
                        "EncryptionMethod",
                        "EncryptionFlags"
                    }, new object[]
                    {
                        4,
                        1
                    }, out managementBaseObject);
                    return;
                }
                returnValue = WMIUtil.CallWMIMethod(encryptableVolume, "Encrypt", new string[]
                {
                    "EncryptionMethod"
                }, new object[]
                {
                    4
                }, out managementBaseObject);
            });
            returnValueEncrypt = returnValue;
            Util.AssertReturnValueExceptionInconsistency(returnValueEncrypt, "Encrypt", ex);
            return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueEncrypt, "Encrypt", ex));
        }