2011-04-01 83 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

相关问题