private string PassWord = "암호(8byte)";
public void EncryptFile(string ReadFilename, string WriteFilename) //파일 암호화
{
FileStream fsInput = new FileStream(ReadFilename, FileMode.Open, FileAccess.Read,FileShare.None);
FileStream fsEncrypted = new FileStream(WriteFilename, FileMode.Create, FileAccess.Write);
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(key);
DES.IV = ASCIIEncoding.ASCII.GetBytes(key);
ICryptoTransform Encrypt = DES.CreateEncryptor();
CryptoStream cryptostream = new CryptoStream(fsEncrypted, Encrypt, CryptoStreamMode.Write);
byte[] bytearrayinput = new byte[fsInput.Length];
fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);
cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);
fsEncrypted.Flush();
cryptostream.Close();
fsInput.Close();
fsEncrypted.Close();
}
public void DecryptFile(string ReadFilename, string WriteFilename)//파일 복호화
{
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(key);
DES.IV = ASCIIEncoding.ASCII.GetBytes(key);
FileStream fsread = new FileStream(ReadFilename, FileMode.Open, FileAccess.ReadWrite,FileShare.ReadWrite);
ICryptoTransform Decrypt = DES.CreateDecryptor();
CryptoStream cryptostreamDecr = new CryptoStream(fsread, Decrypt, CryptoStreamMode.Read);
StreamWriter fsDecrypted = new StreamWriter(WriteFilename);
fsDecrypted.Write(new StreamReader(cryptostreamDecr).ReadToEnd());
fsDecrypted.Flush();
fsDecrypted.Close();
}
출처 : http://kimstar.kr/1193/
시간 구하기 Ticks (0) | 2016.07.12 |
---|---|
.NET CLR Project 만들기 샘플(음력/양력변환) (0) | 2016.02.26 |
파일 사용중인지 확인 (0) | 2016.02.25 |
IP Address, MAC Address 구하기 (0) | 2016.02.25 |
유선 IPv4 Address 구하기 (0) | 2016.02.25 |