예제 #1
0
        public void RijndaelEncrypt()
        {
            ICryptoHelper crytographyHelper = CryptoFactory.Create(CryptographyAlgorithm.Rijndael);

            crytographyHelper.Entropy = ENCRYPTION_VALID_PASSWORD;
            string encryptedString = crytographyHelper.Encrypt(ENCRYPTION_TEST_STRING, StringEncodingType.Hex);

            Assert.IsFalse(StringHelper.Match(encryptedString, ENCRYPTION_TEST_STRING, true), "Encrypted String Equals String Passed In");
        }
예제 #2
0
 /// <summary>
 /// 解密码
 /// </summary>
 /// <param name="Password"></param>
 /// <returns></returns>
 public string GetPwd(string Password)
 {
     try
     {
         return(CryptoFactory.Create(CrytoType.TripleDES).Decrypt(Password));
     }
     catch (Exception ex)
     {
         WriteExceptionLog(ex);
         return("");
     }
 }
예제 #3
0
        public void RijndaelDecryptValidPassword()
        {
            ICryptoHelper crytographyHelper = CryptoFactory.Create(CryptographyAlgorithm.Rijndael);

            crytographyHelper.Entropy = ENCRYPTION_VALID_PASSWORD;
            string encryptedString = crytographyHelper.Encrypt(ENCRYPTION_TEST_STRING, StringEncodingType.Hex);

            ICryptoHelper crytographyHelper2 = CryptoFactory.Create(CryptographyAlgorithm.Rijndael);

            crytographyHelper2.Entropy = ENCRYPTION_VALID_PASSWORD;
            string decriptedString = crytographyHelper2.Decrypt(encryptedString, StringEncodingType.Hex);

            Assert.AreEqual(ENCRYPTION_TEST_STRING, decriptedString);
        }
예제 #4
0
        /// <summary>
        /// 获取FTP配置文件的内容
        /// </summary>
        /// <param name="xmlFileName"></param>
        public FTPConfig(string xmlFileName)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(xmlFileName);

            string      xpath    = @"configuration/FtpConfig";
            XmlNode     node     = xmlDoc.SelectSingleNode(xpath);
            XmlNodeList nodeList = node.ChildNodes;

            if (nodeList != null && nodeList.Count > 0)
            {
                foreach (XmlNode item in nodeList)
                {
                    switch (item.Name)
                    {
                    case "RemoteHost":
                        this.RemoteHost = item.InnerText;
                        break;

                    case "RemotePort":
                        this.RemotePort = item.InnerText;
                        break;

                    case "UserName":
                        this.UserName = item.InnerText;
                        break;

                    case "Password":
                        string pwd = CryptoFactory.Create(CrytoType.TripleDES).Decrypt(item.InnerText);    //三重加密算法--解密
                        this.Password = pwd;
                        break;
                    }
                } //end foreach (XmlNode item in nodeList)
            }     //end if (nodeList != null && nodeList.Count > 0)
        }
예제 #5
0
 /// <summary>
 /// 检查外部网络是否正确
 /// </summary>
 /// <returns></returns>
 public bool CheckExtranetCorrect()
 {
     try
     {
         //外部网络是否连通
         if (!string.IsNullOrEmpty(_mUpdateConfig.ServerUrl))
         {
             //版本号
             bool result = RegexHelper.IsMatch(_mUpdateConfig.ServerUrl, "{VersionNumber}");
             if (result)
             {
                 _mUpdateConfig.ServerUrl = _mUpdateConfig.ServerUrl.Replace("{VersionNumber}", _Version);
             }
             ////企业编号
             //result = RegexHelper.IsMatch(_mUpdateConfig.ServerUrl, "{EnterpriseCode}");
             //if (result)
             //{
             //    _mUpdateConfig.ServerUrl = _mUpdateConfig.ServerUrl.Replace("{EnterpriseCode}", _EnterpriseCode);
             //}
             string address = _mUpdateConfig.ServerUrl; //外部网络地址
             //ftp或http地址
             if (address.StartsWith("ftp"))             //通过ftp更新
             {
                 string[] arrAddress = DataTypeConvert.ToArray(address, '?');
                 if (arrAddress == null || arrAddress.Length != 2)
                 {
                     return(false);
                 }
                 address          = arrAddress[0];
                 address          = address.Replace("ftp://", "");
                 IsFtp            = true;
                 _DicFtpParameter = new Dictionary <string, string>();
                 _DicFtpParameter.Add("RemoteHost", "");
                 _DicFtpParameter.Add("RemotePort", "");
                 _DicFtpParameter.Add("UserName", "");
                 _DicFtpParameter.Add("Password", "");
                 _DicFtpParameter.Add("RemotePath", "");//配置文件所在的目录,如:VersionFiles/V2.1.0.0/0001/Update/Client
                 //获取FTP的登陆用户名和密码
                 string   ftpParam    = arrAddress[1];
                 string[] arrFtpParam = DataTypeConvert.ToArray(ftpParam, '&');
                 if (arrFtpParam == null || arrFtpParam.Length != 2)
                 {
                     return(false);
                 }
                 _DicFtpParameter["UserName"] = arrFtpParam[0];
                 _DicFtpParameter["Password"] = CryptoFactory.Create(CrytoType.TripleDES).Decrypt(arrFtpParam[1]);
             }
             else if (address.StartsWith("http"))//通过http更新
             {
                 IsFtp   = false;
                 address = address.Replace("http://", "");
             }
             //获取主机地址
             string hostAddress = address.Substring(0, address.IndexOf('/'));
             if (hostAddress.Contains(":"))
             {
                 string[] arrHost = DataTypeConvert.ToArray(hostAddress, ':');
                 if (arrHost == null || arrHost.Length != 2)
                 {
                     return(false);
                 }
                 hostAddress = arrHost[0];
                 if (IsFtp)
                 {
                     _DicFtpParameter["RemoteHost"] = arrHost[0];
                     _DicFtpParameter["RemotePort"] = arrHost[1];
                     string remotePath = address.Substring(address.IndexOf('/') + 1);
                     _DicFtpParameter["RemotePath"] = Path.GetDirectoryName(remotePath).Replace("\\", "/");
                 }
             }
             else
             {
                 if (IsFtp)
                 {
                     _DicFtpParameter["RemoteHost"] = hostAddress;
                     _DicFtpParameter["RemotePort"] = "21";
                     string remotePath = address.Substring(address.IndexOf('/') + 1);
                     _DicFtpParameter["RemotePath"] = Path.GetDirectoryName(remotePath).Replace("\\", "/");
                 }
             }
             return(CheckNetwork("www.baidu.com"));//外部网是否连通
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #6
0
 public override void Initialize(IDictionary <string, object> parameters)
 {
     _crypto = CryptoFactory.Create(parameters);
 }