Programmer:)
[WPF/ C#] .ini파일 (DES암호화, 복호화/ UTF8_BOM제거) 본문
반응형
[WPF/ C#] .ini파일 (1. 생성, 쓰기, 읽기)
파일 다운받아 아래 이미지참고하여 추가. 아래 이미지를 참고하여 작성. 쓰기 완성 읽기 코드
ryeggg.tistory.com
위 내용이 되어있다는 전제하에 진행
1.DES Sript생성 후 아래 using문 추가

class DES
{
private byte[] m_key { get; set; }
public string DESEncrypt(string _value)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider()
{
Key = m_key,
IV = m_key
};
//Encoding.UTF8.GetBytes() xxxx BOM 제거하려면 UnicodeEncoding.Unicode.GetBytes 사용
byte[] data = UnicodeEncoding.Unicode.GetBytes(_value);
ICryptoTransform Encrypt = des.CreateEncryptor();
byte[] outdata = Encrypt.TransformFinalBlock(data, 0, data.Length);
return System.Convert.ToBase64String(outdata);
}
public string DESDecrypt(string _value)
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider()
{
Key = m_key,
IV = m_key
};
byte[] data = System.Convert.FromBase64String(_value);
ICryptoTransform Decrypt = des.CreateDecryptor();
byte[] outdata = Decrypt.TransformFinalBlock(data, 0, data.Length);
//Encoding.UTF8.GetBytes() xxxx BOM 제거하려면 UnicodeEncoding.Unicode.GetBytes 사용
return UnicodeEncoding.Unicode.GetString(outdata);
}
//key값은 무조건 8자리!!(중요)
public DES(string _key)
{
m_key = ASCIIEncoding.ASCII.GetBytes(_key);
}
}
사용
//아이디,비밀번호 암호화작업에 사용함.
public void Encryption(string _id, string _password)
{
//암호화작업
DES des = new DES("8자리 key값");
string id = des.DESEncrypt(_id);
string password = des.DESEncrypt(_password);
//ini파일에 암호화된 정보 저장
Write_ini(id, password);
}
//자동로그인구현에 사용
public void Decryption()
{
//복호화
//ini에 저장된 데이터 읽어오기
string[] values = Read_ini();
if (values[0] != null)
{
DES des = new DES("8자리 key값");
_id = des.DESDecrypt(values[0]);
_password = des.DESDecrypt(values[1]);
}
}반응형
'DEV > ETC' 카테고리의 다른 글
| [Mac] UDID 확인법 (0) | 2022.04.29 |
|---|---|
| [Linux - CLI] Terminal 명령어 (0) | 2021.10.18 |
| [WPF/ C#] .ini파일 (1. 생성, 쓰기, 읽기) (0) | 2021.07.06 |
| [WPF] LifeCycle (0) | 2021.03.15 |
| [Windows] 명령프롬프트 명령어 (0) | 2021.03.14 |
Comments