2011-08-22 44 views
1

我想實現加密,因爲有多個人可以訪問數據庫,我的公司希望將人員(敏感)信息存儲在我的應用程序中。爲了創建一些分離和安全性,我希望使用'密鑰'來理想地實現加密,他們選擇加密一個SQL表中的數據。什麼是最適合中小型公司的MSSQL數據庫的加密

我知道自己在做這件事,我會錯過一個竅門,並且經過反覆測試可能是最好的,特別是對於我們這個大小的公司,我們不需要擔心黑客太多,因爲數據庫不是可從外部訪問。足以阻止感興趣的各方。

我想知道什麼樣的安全級別是合適的,而且我甚至有點失落甚至谷歌什麼樣的加密可能在我需要使用的第三方插件,因爲他們都想賣他們的產品他們都會說自己很棒?

我能找到

大多數其他問題和建議的「類似的問題」談到數據傳輸加密,散列或ASP.NET

+2

(「權利」是你想要什麼,而不是「寫」在這裏。)加密是不是最好的,或者最重要的,解決方案的一部分。如果您希望黑客訪問數據庫,那麼除了加密密碼之外,還有其他問題。同樣重要的是,甚至更重要的是保護系統/數據庫,使他們無法訪問它。 –

+0

好吧,我的意圖是'搶佔'信息,'解密'我的C#應用​​程序中的信息,並將'混亂'的信息保存在數據庫中,我們有幾個人正在研究數據庫,我們希望他們在其上開發但只是'爭奪'敏感的東西 – Coops

+1

@Kieren Johnstone,密碼根本不需要存儲:加密或純文本。應該存儲一個(醃製的)密碼散列的密碼,認證應該簡單地比較散列。 –

回答

1

就我個人而言,我會建議使用AES作爲其非常容易實現,並與敏感的個人數據將提供足夠的加密,讓人們不像DES等東西。

本文將詳細深入到AES,如果你想擁有它是如何工作的技術理解:http://msdn.microsoft.com/en-us/magazine/cc164055.aspx ,並隨其基本的例子:http://msdn.microsoft.com/en-us/magazine/cc164846.aspx

如何實現它一個很乾淨的例子是在這裏:http://www.obviex.com/samples/Code.aspx?Source=EncryptionCS&Title=Symmetric%20Key%20Encryption&Lang=C%23

例精簡(爲了防止鏈路羅特)

using System; 
using System.IO; 
using System.Security.Cryptography; 

namespace RijndaelManaged_Examples 
{ 
    class RijndaelMemoryExample 
    { 
     public static void Main() 
     { 
      try 
      { 

       string original = "Here is some data to encrypt!"; 

       // Create a new instance of the RijndaelManaged 
       // class. This generates a new key and initialization 
       // vector (IV). 
       RijndaelManaged myRijndael = new RijndaelManaged(); 

       // Encrypt the string to an array of bytes. 
       byte[] encrypted = encryptStringToBytes_AES(original, myRijndael.Key, myRijndael.IV); 

       // Decrypt the bytes to a string. 
       string roundtrip = decryptStringFromBytes_AES(encrypted, myRijndael.Key, myRijndael.IV); 

       //Display the original data and the decrypted data. 
       Console.WriteLine("Original: {0}", original); 
       Console.WriteLine("Round Trip: {0}", roundtrip); 

      } 
      catch (Exception e) 
      { 
       Console.WriteLine("Error: {0}", e.Message); 
      } 
     } 

     static byte[] encryptStringToBytes_AES(string plainText, byte[] Key, byte[] IV) 
     { 
      // Check arguments. 
      if (plainText == null || plainText.Length <= 0) 
       throw new ArgumentNullException("plainText"); 
      if (Key == null || Key.Length <= 0) 
       throw new ArgumentNullException("Key"); 
      if (IV == null || IV.Length <= 0) 
       throw new ArgumentNullException("Key"); 

      // Declare the streams used 
      // to encrypt to an in memory 
      // array of bytes. 
      MemoryStream msEncrypt = null; 
      CryptoStream csEncrypt = null; 
      StreamWriter swEncrypt = null; 

      // Declare the RijndaelManaged object 
      // used to encrypt the data. 
      RijndaelManaged aesAlg  = null; 

      try 
      { 
       // Create a RijndaelManaged object 
       // with the specified key and IV. 
       aesAlg = new RijndaelManaged(); 
       aesAlg.Key = Key; 
       aesAlg.IV = IV; 

       // Create a decrytor to perform the stream transform. 
       ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); 

       // Create the streams used for encryption. 
       msEncrypt = new MemoryStream(); 
       csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write); 
       swEncrypt = new StreamWriter(csEncrypt); 

       //Write all data to the stream. 
       swEncrypt.Write(plainText); 

      } 
      finally 
      { 
       // Clean things up. 

       // Close the streams. 
       if(swEncrypt != null) 
        swEncrypt.Close(); 
       if (csEncrypt != null) 
        csEncrypt.Close(); 
       if (msEncrypt != null) 
        msEncrypt.Close(); 

       // Clear the RijndaelManaged object. 
       if (aesAlg != null) 
        aesAlg.Clear(); 
      } 

      // Return the encrypted bytes from the memory stream. 
      return msEncrypt.ToArray(); 

     } 

     static string decryptStringFromBytes_AES(byte[] cipherText, byte[] Key, byte[] IV) 
     { 
      // Check arguments. 
      if (cipherText == null || cipherText.Length <= 0) 
       throw new ArgumentNullException("cipherText"); 
      if (Key == null || Key.Length <= 0) 
       throw new ArgumentNullException("Key"); 
      if (IV == null || IV.Length <= 0) 
       throw new ArgumentNullException("Key"); 

      // TDeclare the streams used 
      // to decrypt to an in memory 
      // array of bytes. 
      MemoryStream msDecrypt = null; 
      CryptoStream csDecrypt = null; 
      StreamReader srDecrypt = null; 

      // Declare the RijndaelManaged object 
      // used to decrypt the data. 
      RijndaelManaged aesAlg  = null; 

      // Declare the string used to hold 
      // the decrypted text. 
      string plaintext = null; 

      try 
      { 
       // Create a RijndaelManaged object 
       // with the specified key and IV. 
       aesAlg = new RijndaelManaged(); 
       aesAlg.Key = Key; 
       aesAlg.IV = IV; 

       // Create a decrytor to perform the stream transform. 
       ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); 

       // Create the streams used for decryption. 
       msDecrypt = new MemoryStream(cipherText); 
       csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read); 
       srDecrypt = new StreamReader(csDecrypt); 

       // Read the decrypted bytes from the decrypting stream 
       // and place them in a string. 
       plaintext = srDecrypt.ReadToEnd(); 
      } 
      finally 
      { 
       // Clean things up. 

       // Close the streams. 
       if (srDecrypt != null) 
        srDecrypt.Close(); 
       if (csDecrypt != null) 
        csDecrypt.Close(); 
       if (msDecrypt != null) 
        msDecrypt.Close(); 

       // Clear the RijndaelManaged object. 
       if (aesAlg != null) 
        aesAlg.Clear(); 
      } 

      return plaintext; 

     } 
    } 
} 
0

加密信息可以用對稱(Rijndael算法)來完成的關鍵,但我不不知道爲使用SQL更新的應用程序提高了多少性能。

Symmetric (Rijndael) Key

2

所有的安全實際上是關於提高技術門檻和可用性的權衡。有了加密,這裏有很多選擇,但是這一切都歸結爲關鍵管理。

誰有密鑰解密?

它們是如何存儲的?

對您的應用程序數據進行暴力攻擊(比如說,他們通過攔截您的聯邦快遞到Iron Mountain來獲取加密SQL Server數據庫的備份磁帶)比對密鑰管理系統的內部攻擊實例僱員或開發人員更改程序以解密和轉儲數據。

由於應用程序可能一般必須隨時向授權用戶解密這些數據,因此我可能會專注于敏感列的可見性以及允許先訪問它們的角色,然後擔心加密它們。

SQL Server只提供數據透明加密以及連接加密。如果用戶有SELECT *訪問表,這是沒有用的。在沒有SQL Server知識的列中自己加密可能會有問題。例如,如果一列是付費數據並且很敏感,那麼如果您在列中對其進行加密,則不能只運行SELECT Employee, SUM(Pay) GROUP BY Employee

因此,首先,我將從確保您在應用程序中標識用戶和角色開始,檢查他們擁有什麼樣的訪問權限,並確保與數據庫的所有連接都使用適當的角色。

+0

關於加密數據在實際上並非愚蠢的存儲單元中的有用性降低的好處。 –

相關問題