2016-12-19 70 views
-1

我有一個WinForms應用程序,我正在使用,基本上此刻我有一些數據是使用表單/列表框/文本框創建的,然後將此數據用ecryption密碼加密到文本文件中。用密碼對C#WinForms加密

我有這一切工作順利,真棒,我只是想知道,如果使用這種方法是安全的,在爲它的安全有這個加密方法的文本文件(三倍DES算法):

 //Encryption Method 
     public string EncryptString(string Message, string Passphrase) 
    { 
     byte[] Results; 
     System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding(); 
     MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider(); 
     byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase)); 
     TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider(); 
     TDESAlgorithm.Key = TDESKey; 
     TDESAlgorithm.Mode = CipherMode.ECB; 
     TDESAlgorithm.Padding = PaddingMode.PKCS7; 
     byte[] DataToEncrypt = UTF8.GetBytes(Message); 
     try 
     { 
      ICryptoTransform Encryptor = TDESAlgorithm.CreateEncryptor(); 
      Results = Encryptor.TransformFinalBlock(DataToEncrypt, 0, DataToEncrypt.Length); 
     } 
     finally 
     { 
      TDESAlgorithm.Clear(); 
      HashProvider.Clear(); 
     } 
     return Convert.ToBase64String(Results); 
    } 


    //Decryption Method 
    public string DecryptString(string Message, string Passphrase) 
    { 
     byte[] Results; 
     System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding(); 
     MD5CryptoServiceProvider HashProvider = new MD5CryptoServiceProvider(); 
     byte[] TDESKey = HashProvider.ComputeHash(UTF8.GetBytes(Passphrase)); 
     TripleDESCryptoServiceProvider TDESAlgorithm = new TripleDESCryptoServiceProvider(); 
     TDESAlgorithm.Key = TDESKey; 
     TDESAlgorithm.Mode = CipherMode.ECB; 
     TDESAlgorithm.Padding = PaddingMode.PKCS7; 
     byte[] DataToDecrypt = Convert.FromBase64String(Message); 
     try 
     { 
      ICryptoTransform Decryptor = TDESAlgorithm.CreateDecryptor(); 
      Results = Decryptor.TransformFinalBlock(DataToDecrypt, 0, DataToDecrypt.Length); 
     } 
     finally 
     { 
      TDESAlgorithm.Clear(); 
      HashProvider.Clear(); 
     } 
     return UTF8.GetString(Results); 
    } 
+0

問題應該更適合CodeReview StackExchange – Alejandro

回答