public static bool IsVolumeEncryptionPaused(ManagementObject encryptableVolume, out Exception ex) { int num; BitlockerUtil.BitlockerConversionState bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out num, out ex); return(bitlockerConversionState == BitlockerUtil.BitlockerConversionState.EncryptionPaused); }
public static Exception ValidateAndEncryptEmptyWin8Volume(ManagementObject encryptableVolume, bool fipsCompliant, out int returnValueEncrypt) { int returnValue = -1; returnValueEncrypt = -1; if (encryptableVolume == null) { return(new EncryptableVolumeArgNullException("ValidateAndEncryptEmptyWin8Volume")); } string deviceID = encryptableVolume.GetPropertyValue("DeviceId").ToString(); if (!Util.IsOperatingSystemWin8OrHigher()) { return(new UsedOnlyEncryptionOnNonWin8ServerException(deviceID)); } Exception ex = Util.HandleExceptions(delegate { Exception ex = null; if (!BitlockerUtil.IsVolumeEmpty(deviceID, out ex)) { Util.ThrowIfNotNull(ex); throw new UsedOnlySpaceEncryptionAttemptOnANonEmptyVolumeException(deviceID); } if (!fipsCompliant) { ex = BitlockerUtil.AddNumericalPassword(encryptableVolume, "563563-218372-416746-433752-541937-608069-594110-446754", out returnValue); Util.ThrowIfNotNull(ex); } ex = BitlockerUtil.AddCertificateBasedKeyProtectors(encryptableVolume, out returnValue); Util.ThrowIfNotNull(ex); ex = BitlockerUtil.Encrypt(encryptableVolume, true, out returnValue); Util.ThrowIfNotNull(ex); TimeSpan timeSpan = TimeSpan.FromSeconds(300.0); BitlockerUtil.BitlockerConversionState bitlockerConversionState; while ((bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out returnValue, out ex)) != BitlockerUtil.BitlockerConversionState.FullyEncrypted) { Thread.Sleep(TimeSpan.FromSeconds(1.0)); timeSpan = timeSpan.Subtract(TimeSpan.FromSeconds(1.0)); if (timeSpan.CompareTo(TimeSpan.Zero) < 0) { break; } } if (bitlockerConversionState != BitlockerUtil.BitlockerConversionState.FullyEncrypted) { throw new Win8EmptyVolumeNotFullyEncryptedAfterWaitException(deviceID, 300, bitlockerConversionState.ToString()); } }); returnValueEncrypt = returnValue; return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueEncrypt, "ValidateAndEncryptEmptyWin8Volume", ex)); }
public static Exception ValidateAndEncryptEmptyWin7Volume(ManagementObject encryptableVolume, bool fipsCompliant, out int returnValueEncrypt) { int returnValue = -1; returnValueEncrypt = -1; if (encryptableVolume == null) { return(new EncryptableVolumeArgNullException("ValidateAndEncryptEmptyWin7Volume")); } string deviceID = encryptableVolume.GetPropertyValue("DeviceId").ToString(); if (Util.IsOperatingSystemWin8OrHigher()) { return(new FullVolumeEncryptionOnWin8ServerException(deviceID)); } Exception ex = Util.HandleExceptions(delegate { Exception ex = null; if (!BitlockerUtil.IsVolumeEmpty(deviceID, out ex)) { Util.ThrowIfNotNull(ex); throw new FullVolumeEncryptionAttemptOnANonEmptyVolumeException(deviceID); } string mountPoint; string eventXML; bool flag = BitlockerUtil.DoesVolumeHaveBadBlocks(deviceID, out mountPoint, out ex, out eventXML); if (flag) { throw new Win7EmptyVolumeNotStartedDueToPreviousFailureBadBlocksException(deviceID, mountPoint, eventXML); } if (!fipsCompliant) { ex = BitlockerUtil.AddNumericalPassword(encryptableVolume, "563563-218372-416746-433752-541937-608069-594110-446754", out returnValue); Util.ThrowIfNotNull(ex); } ex = BitlockerUtil.AddCertificateBasedKeyProtectors(encryptableVolume, out returnValue); Util.ThrowIfNotNull(ex); ex = BitlockerUtil.Encrypt(encryptableVolume, false, out returnValue); Util.ThrowIfNotNull(ex); BitlockerUtil.BitlockerConversionState bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out returnValue, out ex); Util.ThrowIfNotNull(ex); if (bitlockerConversionState != BitlockerUtil.BitlockerConversionState.EncryptionInProgress) { throw new Win7EmptyVolumeNotEncryptingAfterStartingEncryptionException(deviceID, bitlockerConversionState.ToString()); } }); returnValueEncrypt = returnValue; return(Util.ReturnWMIErrorExceptionOnExceptionOrError(returnValueEncrypt, "ValidateAndEncryptEmptyWin7Volume", ex)); }
public static Exception IsVolumeEncryptedOrEncrypting(string deviceId, out bool isVolumeEncrypting, out bool isVolumeEncrypted) { isVolumeEncrypting = false; isVolumeEncrypted = false; Exception ex = null; Exception ex2 = null; Exception ex3 = null; if (!BitlockerUtil.IsSystemVolume(deviceId, out ex) && !BitlockerUtil.IsBootVolume(deviceId, out ex2)) { if (ex != null) { return(ex); } if (ex2 != null) { return(ex2); } ManagementObject encryptableVolume = BitlockerUtil.GetEncryptableVolume(deviceId, out ex3); if (encryptableVolume == null) { return(ex3); } int num; BitlockerUtil.BitlockerConversionState bitlockerConversionState = BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out num, out ex3); if (ex3 != null) { return(ex3); } if (bitlockerConversionState != BitlockerUtil.BitlockerConversionState.FullyDecrypted && bitlockerConversionState != BitlockerUtil.BitlockerConversionState.FullyEncrypted && bitlockerConversionState != BitlockerUtil.BitlockerConversionState.EncryptionPaused && bitlockerConversionState != BitlockerUtil.BitlockerConversionState.Unknown) { isVolumeEncrypting = true; } if (bitlockerConversionState == BitlockerUtil.BitlockerConversionState.FullyEncrypted) { isVolumeEncrypted = true; } ExAssert.RetailAssert(!isVolumeEncrypting || !isVolumeEncrypted, DiskManagementStrings.VolumeCannotBeBothEncryptingAndEncrypted(deviceId)); } return(ex3); }
public static bool IsVolumeFullyEncrypted(ManagementObject encryptableVolume, out Exception ex) { int num; return(BitlockerUtil.GetBitlockerConversionState(encryptableVolume, out num, out ex) == BitlockerUtil.BitlockerConversionState.FullyEncrypted); }