private byte[] decrypt3DES(byte[] globalSalt, string masterPwd, byte[] entrySalt, byte[] cipherT) { try { SHA1 sHA = SHA1.Create("sha1"); byte[] array = sHA.ComputeHash(globalSalt); Array.Resize(ref array, 40); Array.Copy(entrySalt, 0, array, 20, 20); byte[] array2 = null; Array.Resize(ref array2, 40); Array.Copy(entrySalt, 0, array2, 20, 20); byte[] key = sHA.ComputeHash(array); HMAC hMAC = HMAC.Create(); hMAC.Key = key; byte[] array3 = hMAC.ComputeHash(array2); Array.Resize(ref array2, 20); byte[] array4 = hMAC.ComputeHash(array2); Array.Resize(ref array4, 40); Array.Copy(entrySalt, 0, array4, 20, 20); byte[] sourceArray = hMAC.ComputeHash(array4); Array.Resize(ref array3, 40); Array.Copy(sourceArray, 0, array3, 20, 20); byte[] iv = array3.Skip(array3.Length - 8).ToArray(); byte[] key2 = array3.Take(24).ToArray(); return(TripleDESHelper.DESCBCDecryptorByte(key2, iv, cipherT).Take(24).ToArray()); } catch (Exception item) { Program.Errors.Add(item); return(null); } }
public byte[] CheckKey3DB(string filePath, string MasterPwd, bool Verbose) { try { Converts converts = new Converts(); Asn1Der asn1Der = new Asn1Der(); BerkeleyDB berkeleyDB = new BerkeleyDB(Path.Combine(filePath, "key3.db")); if (Verbose) { } PasswordCheck passwordCheck = new PasswordCheck(berkeleyDB.Keys.Where(delegate(KeyValuePair <string, string> p) { KeyValuePair <string, string> keyValuePair6 = p; return(keyValuePair6.Key.Equals("password-check")); }).Select(delegate(KeyValuePair <string, string> p) { KeyValuePair <string, string> keyValuePair5 = p; return(keyValuePair5.Value); }).FirstOrDefault() .Replace("-", "")); string hexString = berkeleyDB.Keys.Where(delegate(KeyValuePair <string, string> p) { KeyValuePair <string, string> keyValuePair4 = p; return(keyValuePair4.Key.Equals("global-salt")); }).Select(delegate(KeyValuePair <string, string> p) { KeyValuePair <string, string> keyValuePair3 = p; return(keyValuePair3.Value); }).FirstOrDefault() .Replace("-", ""); if (Verbose) { } MozillaPBE mozillaPBE = new MozillaPBE(converts.ConvertHexStringToByteArray(hexString), Encoding.ASCII.GetBytes(MasterPwd), converts.ConvertHexStringToByteArray(passwordCheck.EntrySalt)); mozillaPBE.Compute(); string text = TripleDESHelper.DESCBCDecryptor(mozillaPBE.Key, mozillaPBE.IV, converts.ConvertHexStringToByteArray(passwordCheck.Passwordcheck)); if (!text.StartsWith("password-check")) { return(null); } string hexString2 = berkeleyDB.Keys.Where(delegate(KeyValuePair <string, string> p) { KeyValuePair <string, string> keyValuePair2 = p; int result; if (!keyValuePair2.Key.Equals("global-salt")) { keyValuePair2 = p; if (!keyValuePair2.Key.Equals("Version")) { keyValuePair2 = p; result = ((!keyValuePair2.Key.Equals("password-check")) ? 1 : 0); goto IL_0043; } } result = 0; goto IL_0043; IL_0043: return((byte)result != 0); }).Select(delegate(KeyValuePair <string, string> p) { KeyValuePair <string, string> keyValuePair = p; return(keyValuePair.Value); }).FirstOrDefault() .Replace("-", ""); Asn1DerObject asn1DerObject = asn1Der.Parse(converts.ConvertHexStringToByteArray(hexString2)); MozillaPBE mozillaPBE2 = new MozillaPBE(converts.ConvertHexStringToByteArray(hexString), Encoding.ASCII.GetBytes(MasterPwd), asn1DerObject.objects[0].objects[0].objects[1].objects[0].Data); mozillaPBE2.Compute(); byte[] dataToParse = TripleDESHelper.DESCBCDecryptorByte(mozillaPBE2.Key, mozillaPBE2.IV, asn1DerObject.objects[0].objects[1].Data); Asn1DerObject asn1DerObject2 = asn1Der.Parse(dataToParse); Asn1DerObject asn1DerObject3 = asn1Der.Parse(asn1DerObject2.objects[0].objects[2].Data); byte[] array = new byte[24]; if (asn1DerObject3.objects[0].objects[3].Data.Length > 24) { Array.Copy(asn1DerObject3.objects[0].objects[3].Data, asn1DerObject3.objects[0].objects[3].Data.Length - 24, array, 0, 24); } else { array = asn1DerObject3.objects[0].objects[3].Data; } return(array); } catch (Exception item) { Program.Errors.Add(item); return(null); } }