Code for retrieving BitLocker recovery key and password - C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.DirectoryServices;
using System.Runtime.InteropServices;
using System.Collections;

namespace ComputerINformation
{
    class BitlockerModel
    {
        

        public string RecoveryGuid { get; set; }
        public string RecoveryPassword { get; set; }


        public BitlockerModel()
        {
            RecoveryGuid = string.Empty;
            RecoveryPassword = string.Empty;
        }

                
    }

    internal class BitlockerLookup
    {
        static DirectoryEntry entryRoot = new DirectoryEntry("LDAP://RootDSE");
        static string domain = String.Format("{0}", entryRoot.Properties["defaultNamingContext"][0]);
        static DirectoryEntry entryDomain = new DirectoryEntry("LDAP://" + domain);


        public List<BitlockerModel> GetBitlockerInfo(string computerName)
        {
            var returnRecoveryInfo = LookupBitlockerRecoveryInfor(computerName);
            return returnRecoveryInfo;
        }

        public static SearchResult FindComputer(string computer)
        {

            entryDomain.AuthenticationType = AuthenticationTypes.Secure|AuthenticationTypes.Sealing|AuthenticationTypes.Signing;
            
            
            using (DirectorySearcher searcher = new DirectorySearcher(entryDomain))
            {
                try
                {
                    searcher.Filter = String.Format(@"(&(objectClass=computer)(anr={0}))", computer);
                    SearchResult result = searcher.FindOne();
                    return result;
                }
                catch (Exception e)
                {
                    return null;
                }
            }
        }
        private static List<BitlockerModel> LookupBitlockerRecoveryInfor(string computerName)
        {

            

            var list = new List<BitlockerModel>();

            SearchResult result = FindComputer(computerName);

            if (result == null)
            {
                
            }
            else
            {

                try
                {
                    Object objValue = Marshal.BindToMoniker(result.GetDirectoryEntry().Path.Replace("GC://","LDAP://"));
                    Type tType = objValue.GetType();
                    tType.InvokeMember("Filter",System.Reflection.BindingFlags.SetProperty|System.Reflection.BindingFlags.Public,null,objValue,
                        new Object[] {"msFVE-RecoveryInformation"});

                    foreach (Object obj in (IEnumerable)objValue)
                    {
                        BitlockerModel blm = new BitlockerModel();
                        blm.RecoveryGuid = new Guid((Byte[])obj.GetType().InvokeMember("msFVE-RecoveryGuid", System.Reflection.BindingFlags.GetProperty | 
                            System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, obj, null, null, null, null)).ToString();
                        blm.RecoveryPassword = obj.GetType().InvokeMember("msFVE-RecoveryPassword", System.Reflection.BindingFlags.GetProperty | 
                            System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance, null, obj, null, null, null, null).ToString();
                        list.Add(blm);

                    }


                }
                catch (Exception e)
                {
                    
                    
                }
            }

            return list;

            
        }
    }

}

2 comments:

  1. Really Liked the information you have provided. I have an article relaed to it. I was searching about it on the internet and I found an amazing article on Pinterest Site. The provided pin was about a site that provides working modded android apps. The name of the site was “Fineapkapps”. The Pin was very halpful, You should read that. Click Here to reach that amazing Pin: Pinterest Modded Apps.

    ReplyDelete
  2. Coin Casino Review | Claim A Free $200 Bonus Today!
    Learn everything you need 인카지노 to know about Coin Casino - worrione how you can claim up to $200 메리트카지노 free bonus today!What is Coin Casino?How good is Coin Casino?

    ReplyDelete