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)); }