시작하려면 객체 지향 프로그래밍을 배우고 있습니다. 좋아, 나는 대칭 알고리즘의 다른 유형으로 콤보 상자가 있습니다.대칭 암호화 알고리즘 함수
private void Form3_Load(object sender, EventArgs e)
{
openencrypt();
comboBox1.Items.Add("AES");
comboBox1.Items.Add("DES");
comboBox1.Items.Add("Rijndael");
comboBox1.Items.Add("RC2");
comboBox1.Items.Add("Triple DES");
comboBox1.SelectedIndex = 0;
}
그런 다음 암호화 기능을 사용하여 어떤 유형인지 확인합니다.
byte[] hpass;
string nFilepath = Set.nfilepath;
FileStream Open = new FileStream(oFilepath, FileMode.Open, FileAccess.Read);
FileStream Save = new FileStream(nFilepath, FileMode.OpenOrCreate, FileAccess.Write);
SHA512 sh512 = new SHA512Managed();
hpass = sh512.ComputeHash(Encoding.ASCII.GetBytes(textBox1.Text));
PasswordDeriveBytes pdb = new PasswordDeriveBytes(hpass, hash);
if (comboBox1.SelectedIndex.Equals(0))
{
Aes alg = Aes.Create();
alg.Key = pdb.GetBytes(32);
alg.IV = pdb.GetBytes(16);
}
if (comboBox1.SelectedIndex.Equals(1))
{
DES alg = DES.Create();
alg.Key = pdb.GetBytes(32);
alg.IV = pdb.GetBytes(16);
}
if (comboBox1.SelectedIndex.Equals(2))
{
Rijndael alg = Rijndael.Create();
alg.Key = pdb.GetBytes(32);
alg.IV = pdb.GetBytes(16);
}
그러나 각 if 문에 암호 스트림을 넣고 싶지 않을 때. 그렇다면 함수에 체크를 오프로드하여 대칭 알고리즘 유형을 반환하는 방법이 있습니까? 열쇠와 IV로? 나는 이것에 대해 완전히 잘못된 건가 ## 될 ##
아마도 추상 기본 클래스가 아닌 인터페이스를 사용해야합니다. –
@WillVousden - 문법 전체를 생략했습니다. – ChaosPandion
@WillVousden 좋은 지적. 나는 동의한다. –