2011-04-01 65 views
0

我需要將登錄憑證保護到特權帳戶,以便在適當的條件下可以通過某種腳本訪問它們。如何加密數據以便許多用戶可以解密它?

簡單的答案可能是在app.config中對它們進行加密,但是然後它們可以被任何用戶訪問,並且只能在被加密的機器上訪問。我需要通過Subversion分發這個配置,以便源代碼將在任何可用的構建服務器上編譯,並且構建腳本可以訪問加密的數據。構建用戶將被認識(可能位於不同的域),但每次都會有不同的機器。

可以使用證書嗎?沒有CA?另一種方法?

寧願在C#中這樣做,以便它可以耦合到一個MSBuild任務。爲了安全起見,我不想將解密的數據寫入文件系統。

想法?

回答

0

能夠「分配」密鑰/加密信息並允許某些用戶訪問該設備的步驟與DRM幾乎完全相同,但它們仍然沒有「解決」此問題:)

無論如何,我想知道這個解決方案是否可以爲你們工作?

  1. 在機器上設置加密信息所在的訪問列表,並且只允許構建服務器訪問它。
  2. 現在在「用戶」訪問它的問候,似乎暗示同一用戶將需要訪問,但通過不同的生成機器?如果是這樣的話,我認爲有可能在這些用戶帳戶中嵌入密鑰來解密加密的登錄信息,這些用戶帳戶應該有權訪問此帳戶。例如在Windows中,您具有訪問管理權限並可以加密用戶帳戶信息。

所以基本上,這導致我提出一個雙叉解決方案,它是可以訪問這些信息誰需要能夠運行該腳本的機器,和用戶的白名單可以有鑰匙嵌入到他們的個人資料?

1

不對稱加密是你需要的。

這裏是RSA算法的MSDN文檔的鏈接,它將起作用。

http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.aspx

這是他們在頁面底部提供樣品。

static void Main() 
{ 
    try 
    { 
     //Create a UnicodeEncoder to convert between byte array and string. 
     UnicodeEncoding ByteConverter = new UnicodeEncoding(); 

     //Create byte arrays to hold original, encrypted, and decrypted data. 
     byte[] dataToEncrypt = ByteConverter.GetBytes("Data to Encrypt"); 
     byte[] encryptedData; 
     byte[] decryptedData; 

     //Create a new instance of RSACryptoServiceProvider to generate 
     //public and private key data. 
     using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) 
     { 

      //Pass the data to ENCRYPT, the public key information 
      //(using RSACryptoServiceProvider.ExportParameters(false), 
      //and a boolean flag specifying no OAEP padding. 
      encryptedData = RSAEncrypt(dataToEncrypt, RSA.ExportParameters(false), false); 

      //Pass the data to DECRYPT, the private key information 
      //(using RSACryptoServiceProvider.ExportParameters(true), 
      //and a boolean flag specifying no OAEP padding. 
      decryptedData = RSADecrypt(encryptedData, RSA.ExportParameters(true), false); 

      //Display the decrypted plaintext to the console. 
      Console.WriteLine("Decrypted plaintext: {0}", ByteConverter.GetString(decryptedData)); 
     } 
    } 
    catch (ArgumentNullException) 
    { 
     //Catch this exception in case the encryption did 
     //not succeed. 
     Console.WriteLine("Encryption failed."); 

    } 
} 

static public byte[] RSAEncrypt(byte[] DataToEncrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding) 
{ 
    try 
    { 
     byte[] encryptedData; 
     //Create a new instance of RSACryptoServiceProvider. 
     using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) 
     { 

      //Import the RSA Key information. This only needs 
      //toinclude the public key information. 
      RSA.ImportParameters(RSAKeyInfo); 

      //Encrypt the passed byte array and specify OAEP padding. 
      //OAEP padding is only available on Microsoft Windows XP or 
      //later. 
      encryptedData = RSA.Encrypt(DataToEncrypt, DoOAEPPadding); 
     } 
     return encryptedData; 
    } 
    //Catch and display a CryptographicException 
    //to the console. 
    catch (CryptographicException e) 
    { 
     Console.WriteLine(e.Message); 

     return null; 
    } 

} 

static public byte[] RSADecrypt(byte[] DataToDecrypt, RSAParameters RSAKeyInfo, bool DoOAEPPadding) 
{ 
    try 
    { 
     byte[] decryptedData; 
     //Create a new instance of RSACryptoServiceProvider. 
     using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider()) 
     { 
      //Import the RSA Key information. This needs 
      //to include the private key information. 
      RSA.ImportParameters(RSAKeyInfo); 

      //Decrypt the passed byte array and specify OAEP padding. 
      //OAEP padding is only available on Microsoft Windows XP or 
      //later. 
      decryptedData = RSA.Decrypt(DataToDecrypt, DoOAEPPadding); 
     } 
     return decryptedData; 
    } 
    //Catch and display a CryptographicException 
    //to the console. 
    catch (CryptographicException e) 
    { 
     Console.WriteLine(e.ToString()); 

     return null; 
    } 

} 

}

+0

但是我仍然關心如何*管理*爲這些用戶的關鍵在於能夠因此解密我認爲有一個可以連接也將有助於機器的白名單。 – Pharaun 2011-04-02 00:36:55

相關問題