분노의 챔질
C# 암호화 본문
private void btnEncryption_Click(object sender, EventArgs e)
{
this.txtPassWord.Text = PasswordEncryption();
}
private void btnDecryption_Click(object sender, EventArgs e)
{
this.txtPassWord.Text = DecryptString(txtPassWord.Text, "ABCD");
}
private string PasswordEncryption()
{
string EncryptedPassword = string.Empty;
return EncryptedPassword;
}
public string DecryptString(string InputText, string Password)
{
RijndaelManaged RijndaelCipher = new RijndaelManaged();
byte[] EncryptedData = Convert.FromBase64String(InputText);
byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString());
PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt);
ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16));
MemoryStream memoryStream = new MemoryStream(EncryptedData);
CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
byte[] PlainText = new byte[EncryptedData.Length];
int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length);
memoryStream.Close();
cryptoStream.Close();
string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount);
return DecryptedData;
}
'Programming > C#' 카테고리의 다른 글
C# LINQ 쿼리식 (0) | 2010.02.24 |
---|---|
C# XML 만들기, 읽기 (0) | 2010.02.23 |
C# DB연결하기 (0) | 2010.02.23 |
C# Assembly.LoadFrom() DLL불러오기 (0) | 2010.02.23 |
C# PDF파일 다루기 (1) | 2010.02.23 |