FTP FileZilla Server 本地加密C# 實現

來源:互聯網
上載者:User

標籤:verilog   webserver   參考   root   9.png   document   string   公司   對比   

最近公司要做一個資料管理模組,因系統是C/S架構,原來小檔案都是直接使用7Z壓縮後儲存到SQL Server資料庫

而資料管理模組也就是檔案上傳,下載加許可權管理,考慮檔案較多,還可能比較大,所以打算在伺服器上直接儲存檔案。

C/S上傳檔案到伺服器,我知道的有幾個實現方法:

  1、使用IIS服務,通過B/S方式上傳到伺服器。這種方式需要伺服器上部署IIS,提供WebServers服務,上傳檔案到指定目錄後進行資料庫編碼儲存。

  2、使用FTP服務,服務端安裝FTP伺服器,用戶端使用FTP類進行訪問,好處是如果以後需要檔案管理,可以直接使用現有的用戶端進行管理。

  3、使用TCP通訊方式上傳下載。這種方式還需要處理很多問題。

經過幾番尋找,對比,決定使用第二種方式,使用開源的FileZilla 進行管理

使用FTP方式,就必須能實現服務端能在程式中控制,比如,在系統中添加使用者,則伺服器也同時能對FTP服務端添加使用者操作,及許可權分配。

經研究FileZilla Server使用XML設定檔管理,其分支結構非常清晰。

 

這是V9.46版本的設定檔,最新版本V9.60已修改了加密方式,添加了SHA512加密,方法還是一樣,也可以直接使用C#產生。

 static string md5(string a)
        {
            string pwd = "";
            MD5 md5 = MD5.Create();
            byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(a));
            for (int i = 0; i < s.Length; i++)
            {
                pwd = pwd + s[i].ToString("x2"); 
            }           
            return pwd;       
        }

 此方法來源:http://blog.sina.com.cn/s/blog_589b38e70100rtse.html

修改設定檔後需要重新載入,使設定檔生效:

官方手冊使用命令列方式    /reload-config 命令就可以重新載入資料了

-------------- "FileZilla Server.exe" Command-line arguments  ------------------Starting and stopping the service:

/start/stop

Installing the service for manual startup:

/install

Installing the service for start at boot:

/install auto

Uninstalling service:

/uninstall

Reloading configuration at runtime:

/reload-config

 重新載入參考:http://www.tuicool.com/articles/AzQBfmU

 

最新版本V6.0以後 密碼產生:

 

代碼:

string [email protected]"<Root><salt>&lt;RhUrxf^l,VZ&amp;7I/[email protected]\p&apos;^cEmPEWyYMjS8^&amp;HY1Z|J.2#u2Z}]HF0i9</salt></Root>";
XmlDocument xmldoc=new XmlDocument();
xmldoc.LoadXml(txt);

string oldPass="05087D2082B206535713C1D5BDCA35509BE70B8C4F513F7E5F9799187DCB7F366011DB51AFACC67D1035A8EE7C04C6C12E92A4330808DDA4FF9F9946A09076FA";
string pass="123";
string salt=xmldoc.ChildNodes[0].InnerText;
salt.Dump();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(pass+salt);

SHA512 sha512 = new SHA512CryptoServiceProvider();
byte[] retVal = sha512.ComputeHash(bytValue);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("X2"));
}


bool isComp= ( oldPass==sb.ToString());
isComp.Dump();

 

FTP FileZilla Server 本地加密C# 實現

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.