我想实施加密,因为有多个人可以访问数据库,而我的公司希望在我的应用程序中存储人员(敏感)信息。为了创建一些分离和安全性,我想理想地使用“密钥”实现加密,他们选择加密一个SQL表中的数据。
我知道自己这样做,我会错过一个技巧,经过试验和测试可能是最好的,特别是对于我们这样规模的公司,我们不需要太担心黑客,因为数据库不是外部的无障碍。足以阻止有兴趣的各方。
我想知道什么级别的安全性是合适的,而且我有点迷失甚至谷歌甚至可以找到我需要使用的第三方插件中的哪种加密方式,因为他们都想卖掉他们的他们都会说自己的产品很棒?
我能找到的大多数其他问题以及建议的“类似问题”都谈到了数据传输加密,散列或ASP.NET
答案 0 :(得分:2)
所有安全措施都是为了提高标准和可用性权衡。通过加密,这里有很多选项,但它实际上都归结为密钥管理。
谁拥有解密密钥?
他们是如何存储的?
对您的应用程序数据进行暴力攻击(比如他们通过拦截您的FedEx到Iron Mountain来获取加密的SQL Server数据库的备份磁带)不太可能比对密钥管理系统的内部攻击 - 例如员工或开发人员改变程序以解密和转储数据。
因为应用程序通常必须随时向授权用户解密这些数据,所以我可能会集中精力查看敏感列的可见性以及允许首先访问它们的角色,然后担心加密它们。 / p>
SQL Server仅为数据提供透明加密,并为连接提供加密。如果用户具有SELECT *
对表的访问权限,则此功能无效。在没有SQL Server知识的情况下在列中自己加密可能会有问题。例如,如果一列是付费数据且敏感,如果您在列中对其进行加密,则不能只运行SELECT Employee, SUM(Pay) GROUP BY Employee
首先,我首先要确保您已在应用程序中识别用户和角色,查看他们拥有的访问权限,并确保与数据库的所有连接都使用适当的角色。
答案 1 :(得分: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;
}
}
}
答案 2 :(得分:0)
可以使用Symmetric(Rijndael)密钥完成加扰信息,但我不知道使用SQL更新的应用程序的性能有多大提升。