개인적으로 AES는 아주 쉽게 구현할 수 있으며 민감한 개인 데이터는 DES와는 달리 사람들을 보호 할 수있는 충분한 암호화를 제공합니다.http://msdn.microsoft.com/en-us/magazine/cc164055.aspx 과 함께 제공되는 기본 예제 : http://msdn.microsoft.com/en-us/magazine/cc164846.aspx이
를 구현하는 방법의 매우 깨끗 예를 들어 여기에 당신이 어떻게 작동하는지에 대한 기술적 이해를 갖고 싶어
이 문서에서는 AES로 깊이 간다 : 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;
}
}
}
(링크 ROTT을 방지하기 위해) 옷을 벗었 암호화는 가장 중요한 최고의, 또는 아니다, 솔루션의 일부 해커가 DB에 액세스 할 것으로 예상하는 경우 암호를 암호화하는 것 외에 다른 문제가 있습니다. 마찬가지로 중요한 것은 시스템/데이터베이스가 액세스 할 수 없도록 시스템/데이터베이스의 보안을 유지하는 것입니다. –
좋아요, 제 의도는 정보를 '스크램블 (scramble)'하고 C# 응용 프로그램의 정보를 '디 스크램블 (descramble)'하고 데이터베이스에 '스크램블 드'정보를 저장하는 것이 었습니다. 우리는 DB에서 작업하는 사람들이 몇 명 있으며, 민감한 내용을 '스크램블'합니다. – Coops
@Kieren Johnstone, 암호는 암호화되거나 일반 텍스트로 저장 될 필요가 없습니다. 하나는 (소금에 절인) 암호 해시 암호를 저장해야하며 인증은 단순히 해시를 비교해야합니다. –