Nghiên cứu kỹ thuật chữ ký số và ứng dụng

89 178 0
Nghiên cứu kỹ thuật chữ ký số và ứng dụng

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC BÁCH KHOA HÀ NỘI - Học viên: Nguyễn Thị Phương Hoa Nghiên cứu kỹ thuật chữ ký số ứng dụng LUẬN VĂN THẠC SỸ KHOA HỌC Chuyên ngành: Kỹ thuật điện tử Hà nội - năm 2010 Lời nói đầu Bảo mật thông tin vấn đề quan trọng hàng đầu lĩnh vực tình báo, quân sự, ngoại giao, vấn đề nghiên cứu hàng nghìn năm Ngày nay, thương mại điện tử coi yếu tố quan trọng giúp doanh nghiệp giữ vững mở rộng thị trường, tăng tính cạnh tranh, thực thỏa thuận thương mại khu vực giới Tất trình đòi hỏi lượng thông tin trao đổi lớn qua mạng, đồng thời yêu cầu độ an toàn tính xác thực cao Việc ứng dụng chữ ký điện tử công nhận giá trị pháp lý điều kiện tiên cho thương mại điện tử phát triển Với đề tài Nghiên cứu kỹ thuật chữ ký số ứng dụng, luận văn em bao gồm phần sau: Chương 1: Cơ sở lý thuyết toán học Chương 2: Tổng quan lý thuyết mã hóa liệu Chương 3: Tổng quan chữ ký số sở pháp lý Chương 4: Giải pháp ứng dụng chữ ký số vào hệ thống quản lý văn Chương 5: Xây dựng phần mềm khóa số văn Sau thời gian hướng dẫn tận tình thầy giáo – TS Nguyễn Tiến Dũng, đến luận văn em hoàn thành Trước hết, em xin bày tỏ lòng biết ơn sâu sắc đến thầy giáo hướng dẫn thầy cô giáo trực tiếp giảng dạy hướng dẫn, giúp đỡ em hoàn thành luận văn Em xin chân thành cảm ơn giúp đỡ thầy cô giáo khoa Điện tử Viễn thông thầy cô công tác Viện đào tạo sau Đại học, Trường Đại học Bách Khoa Hà Nội, tạo giúp đỡ, tạo điều kiện thuận lợi thời gian em thực luận văn MỤC LỤC Danh mục ký hiệu, viết tắt Danh mục hình vẽ đồ thị .8 CHƯƠNG MỞ ĐẦU Chương 1- CƠ SỞ LÝ THUYẾT TOÁN HỌC 13 1.1 Lý thuyết thông tin 13 1.1.1 Entropy .13 1.1.2 Tốc độ ngôn ngữ 14 1.1.3 An toàn hệ thống mã hóa .14 1.1.4 Sự lộn xộn rườm rà 15 1.2 Lý thuyết độ phức tạp 15 1.3 Các phép kiểm tra số nguyên tố 16 1.3.1 Soloway Trassen .16 1.3.2 Rabin Miller 18 1.3.3 Lehmann .18 1.3.4 Strong Primes .19 Chương – TỔNG QUAN VỀ LÝ THUYẾT MÃ HÓA DỮ LIỆU .20 2.1 Khái niệm mã hóa 20 2.1.1 Giới thiệu lịch sử mã hóa 20 2.1.2 Khái niệm mã hóa liệu .21 2.2 Các hệ mã hóa 23 2.2.1 Mã hóa không khóa (hàm băm) 24 2.2.2 Mã hóa đối xứng 25 2.2.3 Mã hóa khóa công khai 26 2.3 Khái niệm khóa .28 2.3.1 Độ dài khóa 28 2.3.2 Quản lý khóa 29 2.4 Một số thuật toán mã hóa 30 2.4.1 Thuật toán hàm băm MD5 30 2.4.2 Thuật toán RSA 36 2.4.3 Thuật toán DES 38 Chương – TỔNG QUAN VỀ CHỮ KÝ SỐ VÀ CƠ SỞ PHÁP LÝ .43 3.1 Định nghĩa chữ ký số 43 3.2 Cơ sở pháp lý chữ ký số 43 3.3 Ứng dụng chữ ký số 45 3.4 Nguyên tắc hoạt động chữ ký số 46 Chương 4-GIẢI PHÁP ỨNG DỤNG CHỮ KÝ SỐ GỬI NHẬN VĂN BẢN 50 4.1 Lựa chọn giải pháp 50 4.2 Quá trình ký gửi tệp văn 51 4.3 Quá trình nhận tệp văn 52 Chương – XÂY DỰNG PHẦN MỀM KÝ SỐ VĂN BẢN SI-TEXT 54 5.1 Giới thiệu phần mềm Si-Text 54 5.2 Các bước thực xây dựng phần mềm 55 5.2.1 Giải thuật tạo khóa công khai bí mật 55 5.2.2 Giải thuật mã hóa giải mã file văn 56 5.2.3 Khởi tạo form thực chức .57 5.3 Hướng dẫn sử dụng demo phần mềm .59 5.3.1 Cài đặt phần mềm 59 5.3.2 Đăng ký tài khoản .61 5.3.3 Mã hóa file 63 5.3.4 Giải mã file .64 KẾT LUẬN .67 TÀI LIỆU THAM KHẢO .69 PHỤ LỤC – CHI TIẾT CODE C# CỦA PHẦN MỀM .70 DANH MỤC CÁC KÝ HIỆU VIẾT TẮT MD Message Digest SHA Secure Hash Alogorithm RSA R.Rivets, A.Shamir, L.Adleman DES Data Encryption Standard CA Certificate Authority GPEA Government Paperwork Elimination Act ESIGN Electronic Signatures in Global and National Commerce UETA Uniform Electronic Transactions Act DN Doanh nghiệp DANH MỤC CÁC HÌNH VẼ ĐỒ THỊ Hình 1.1 Mô hình trao đổi thông tin qua mạng theo cách thông thường .10 Hình 1.2 Mô hình trao đổi thông tin theo phương pháp mã hóa khóa công khai 11 Hình 2.1 Quá trình mã hóa giải mã liệu 22 Hình 2.2 Sơ đồ phân loại phương pháp mã hóa liệu 23 Hình 2.3 Quá trình băm liệu .24 Hình 2.4 Mã hóa giải mã với khóa đối xứng .26 Hình 2.5 Mã hoá giải mã với hai khoá 27 Hình 2.6 Thực nhồi liệu 32 Hình 2.7 Thực thêm độ dài .32 Hình 2.8 Xử lý khối liệu 512 bit 34 Hình 2.9 Giải thuật MD5 36 Hình 2.10 Giải thuật RSA 38 Hình 2.11 Giải thuật DES 40 Hình 3.1 Sơ đồ hoạt động chữ ký số 48 Hình 4.1 Mô hình mã hóa giải mã văn điện tử phương pháp mã hóa khóa công khai 50 Hình 4.2 Quá trình ký tệp văn 52 Hình 4.3 Quá trình nhận kiểm tra tệp văn 53 Hình 5.1 Form đăng ký tạo cặp khóa cho người gửi 58 Hình 5.2 Form tạo file mã hóa 58 Hình 5.3 Form thực giải mã file .59 Hình 5.4 Giao diện cài đặt NET Frame 60 Hình 5.5 Tạo cặp khóa .62 Hình 5.6 Thông báo tạo cặp khóa thành công 62 Hình 5.7 Thay đổi thông tin cặp khóa 63 Hình 5.8 Thực mã hóa file .64 Hình 5.9 Thực giải mã file .65 Hình 5.10 Thông báo nhập khóa sai 66 CHƯƠNG MỞ ĐẦU Cơ sở khoa học thực tiễn đề tài Ngày nay, ứng dụng Công nghệ thông tin ngày phổ biến rộng rãi ảnh hưởng lớn đến diện mạo đời sống, kinh tế, xã hội Mọi công việc hàng ngày thực từ xa với hỗ trợ máy vi tính mạng internet (từ việc học tập, mua sắm, gửi thư…) Tất thông tin liên quan đến công việc máy vi tính quản lý truyền hệ thống mạng Đối với thông tin bình thường ý đến, với thông tin mang tính chất sống số cá nhân (hay tổ chức) vấn đề bảo mật thật quan trọng Nhiều tổ chức, cá nhân tìm kiếm đưa nhiều giải pháp bảo mật; phương pháp ứng dụng chữ ký số với tảng mã hóa khóa công khai xem phương pháp có tính an toàn cao Thông thường việc trao đổi thông tin hai người mô tả hình 1.1, bước thực sau: - Tạo thông tin cần gửi - Gửi thông tin cho đối tác Theo cách quản lý bí mật thông tin người thứ ba không mong muốn đón thông tin Vì ta xây dựng mô hình trao đổi thông tin bảo mật hình 1.2, bước thực sau: 10 - Tạo thông tin cần gửi - Mã hóa gửi thông tin mã hóa - Đối tác giải mã thông tin nhận - Đối tác có thông tin ban đầu người gởi Đây mô hình ứng dụng chữ ký số việc gửi nhận văn bản, sở khoa học thực tiễn để đề tài xây dựng nghiên cứu nhằm phát triển phần mềm ứng dụng bảo mật văn theo mô hình 1.2 Mục tiêu đề tài Trên sở khoa học thực tiễn trên, luận văn tập trung nghiên cứu nội dung lý thuyết mã hóa, thuật toán mã hóa tìm hiểu nguyên tắc hoạt động chữ ký số Từ xây dựng phát triển phần mềm ứng dụng chữ ký số gửi nhận văn Phần mềm đặt tên phần mềm ký số văn Si-Text Mã hóa nói chung chữ ký số nói riêng phạm trù phức tạp ngày phát triển tinh vi Vì vậy, đề tài cố gắng tập trung trình bày đơn giản, dễ hiểu ngắn gọn nội dung lý thuyết cô đọng để người đọc có nhìn tổng quan toàn diện vấn đề mã hóa liệu Và giúp hiểu rõ tảng lý thuyết nhận thức rõ vai trò mã hóa sống, đề tài xây dựng phần mềm ký số văn Si-Text phiên thử 11 this.txtpathchuyky.Location = new System.Drawing.Point(117, 102); this.txtpathchuyky.Name = "txtpathchuyky"; this.txtpathchuyky.Size = new System.Drawing.Size(184, 20); this.txtpathchuyky.TabIndex = 23; // // label15 // this.label15.AutoSize = true; this.label15.Location = new System.Drawing.Point(30, 109); this.label15.Name = "label15"; this.label15.Size = new System.Drawing.Size(79, 13); this.label15.TabIndex = 22; this.label15.Text = "Lưu file chữ ký:"; // // Label4 // this.Label4.Location = new System.Drawing.Point(21, 38); this.Label4.Name = "Label4"; this.Label4.Size = new System.Drawing.Size(88, 16); this.Label4.TabIndex = 20; this.Label4.Text = "File mã hóa:"; this.Label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // btnFileEncrypt // this.btnFileEncrypt.Enabled = false; this.btnFileEncrypt.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnFileEncrypt.Location = new System.Drawing.Point(313, 138); this.btnFileEncrypt.Name = "btnFileEncrypt"; this.btnFileEncrypt.Size = new System.Drawing.Size(72, 21); this.btnFileEncrypt.TabIndex = 19; this.btnFileEncrypt.Text = "Mã hóa"; this.btnFileEncrypt.Click += new System.EventHandler(this.btnFileEncrypt_Click); // // txtPassEncrypt // this.txtPassEncrypt.Enabled = false; this.txtPassEncrypt.Location = new System.Drawing.Point(117, 70); this.txtPassEncrypt.Name = "txtPassEncrypt"; this.txtPassEncrypt.Size = new System.Drawing.Size(184, 20); this.txtPassEncrypt.TabIndex = 17; // // Label1 // this.Label1.Location = new System.Drawing.Point(21, 14); this.Label1.Name = "Label1"; this.Label1.Size = new System.Drawing.Size(90, 20); this.Label1.TabIndex = 16; this.Label1.Text = "File cần mã hóa:"; 76 this.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Label2 // this.Label2.Location = new System.Drawing.Point(21, 70); this.Label2.Name = "Label2"; this.Label2.Size = new System.Drawing.Size(88, 16); this.Label2.TabIndex = 14; this.Label2.Text = "Khóa bí mật:"; this.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // btnBrowseEncrypt // this.btnBrowseEncrypt.Location = new System.Drawing.Point(313, 14); this.btnBrowseEncrypt.Name = "btnBrowseEncrypt"; this.btnBrowseEncrypt.Size = new System.Drawing.Size(72, 21); this.btnBrowseEncrypt.TabIndex = 13; this.btnBrowseEncrypt.Text = "Browse"; this.btnBrowseEncrypt.Click += new System.EventHandler(this.btnBrowseEncrypt_Click); // // txtFileToEncrypt // this.txtFileToEncrypt.Location = new System.Drawing.Point(117, 14); this.txtFileToEncrypt.Name = "txtFileToEncrypt"; this.txtFileToEncrypt.ReadOnly = true; this.txtFileToEncrypt.Size = new System.Drawing.Size(184, 20); this.txtFileToEncrypt.TabIndex = 12; this.txtFileToEncrypt.Text = "Click Browse to load file."; // // tabFileDecryption // this.tabFileDecryption.Controls.Add(this.cmdchonfilechukygiaima); this.tabFileDecryption.Controls.Add(this.txtfilepathopenchuky); this.tabFileDecryption.Controls.Add(this.label16); this.tabFileDecryption.Controls.Add(this.txtDestinationDecrypt); this.tabFileDecryption.Controls.Add(this.Label5); this.tabFileDecryption.Controls.Add(this.btnFileDecrypt); this.tabFileDecryption.Controls.Add(this.txtConPassDecrypt); this.tabFileDecryption.Controls.Add(this.txtPassDecrypt); this.tabFileDecryption.Controls.Add(this.Label6); this.tabFileDecryption.Controls.Add(this.Label7); this.tabFileDecryption.Controls.Add(this.Label8); this.tabFileDecryption.Controls.Add(this.btnBrowseDecrypt); this.tabFileDecryption.Controls.Add(this.txtFileToDecrypt); this.tabFileDecryption.Location = new System.Drawing.Point(4, 22); this.tabFileDecryption.Name = "tabFileDecryption"; 77 this.tabFileDecryption.Size = new System.Drawing.Size(393, 165); this.tabFileDecryption.TabIndex = 2; this.tabFileDecryption.Text = "Giải mã file"; this.tabFileDecryption.UseVisualStyleBackColor = true; // // cmdchonfilechukygiaima // this.cmdchonfilechukygiaima.Location = new System.Drawing.Point(307, 68); this.cmdchonfilechukygiaima.Name = "cmdchonfilechukygiaima"; this.cmdchonfilechukygiaima.Size = new System.Drawing.Size(75, 23); this.cmdchonfilechukygiaima.TabIndex = 35; this.cmdchonfilechukygiaima.Text = "Chọn file chữ ký"; this.cmdchonfilechukygiaima.UseVisualStyleBackColor = true; this.cmdchonfilechukygiaima.Click += new System.EventHandler(this.cmdchonfilechukygiaima_Click); // // txtfilepathopenchuky // this.txtfilepathopenchuky.Location = new System.Drawing.Point(115, 69); this.txtfilepathopenchuky.Name = "txtfilepathopenchuky"; this.txtfilepathopenchuky.Size = new System.Drawing.Size(184, 20); this.txtfilepathopenchuky.TabIndex = 34; // // label16 // this.label16.AutoSize = true; this.label16.Location = new System.Drawing.Point(21, 73); this.label16.Name = "label16"; this.label16.Size = new System.Drawing.Size(86, 13); this.label16.TabIndex = 33; this.label16.Text = "Chọn file chữ ký:"; // // txtDestinationDecrypt // this.txtDestinationDecrypt.Location = new System.Drawing.Point(115, 43); this.txtDestinationDecrypt.Name = "txtDestinationDecrypt"; this.txtDestinationDecrypt.ReadOnly = true; this.txtDestinationDecrypt.Size = new System.Drawing.Size(184, 20); this.txtDestinationDecrypt.TabIndex = 32; // // Label5 // this.Label5.Location = new System.Drawing.Point(19, 43); this.Label5.Name = "Label5"; this.Label5.Size = new System.Drawing.Size(88, 16); this.Label5.TabIndex = 31; this.Label5.Text = "File giải mã:"; this.Label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // 78 // btnFileDecrypt // this.btnFileDecrypt.Enabled = false; this.btnFileDecrypt.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.btnFileDecrypt.Location = new System.Drawing.Point(307, 116); this.btnFileDecrypt.Name = "btnFileDecrypt"; this.btnFileDecrypt.Size = new System.Drawing.Size(72, 25); this.btnFileDecrypt.TabIndex = 30; this.btnFileDecrypt.Text = "Giải mã"; this.btnFileDecrypt.Click += new System.EventHandler(this.btnFileDecrypt_Click); // // txtConPassDecrypt // this.txtConPassDecrypt.Location = new System.Drawing.Point(115, 121); this.txtConPassDecrypt.Name = "txtConPassDecrypt"; this.txtConPassDecrypt.PasswordChar = '*'; this.txtConPassDecrypt.Size = new System.Drawing.Size(184, 20); this.txtConPassDecrypt.TabIndex = 29; // // txtPassDecrypt // this.txtPassDecrypt.Location = new System.Drawing.Point(115, 97); this.txtPassDecrypt.Name = "txtPassDecrypt"; this.txtPassDecrypt.PasswordChar = '*'; this.txtPassDecrypt.Size = new System.Drawing.Size(184, 20); this.txtPassDecrypt.TabIndex = 28; // // Label6 // this.Label6.Location = new System.Drawing.Point(10, 18); this.Label6.Name = "Label6"; this.Label6.Size = new System.Drawing.Size(97, 20); this.Label6.TabIndex = 27; this.Label6.Text = "File cần giải mã:"; this.Label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Label7 // this.Label7.Location = new System.Drawing.Point(3, 121); this.Label7.Name = "Label7"; this.Label7.Size = new System.Drawing.Size(104, 16); this.Label7.TabIndex = 26; this.Label7.Text = "Nhập lại khóa:"; this.Label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // Label8 // this.Label8.Location = new System.Drawing.Point(19, 97); 79 this.Label8.Name = "Label8"; this.Label8.Size = new System.Drawing.Size(88, 16); this.Label8.TabIndex = 25; this.Label8.Text = "Khóa công khai:"; this.Label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // btnBrowseDecrypt // this.btnBrowseDecrypt.Location = new System.Drawing.Point(307, 19); this.btnBrowseDecrypt.Name = "btnBrowseDecrypt"; this.btnBrowseDecrypt.Size = new System.Drawing.Size(72, 21); this.btnBrowseDecrypt.TabIndex = 24; this.btnBrowseDecrypt.Text = "Browse"; this.btnBrowseDecrypt.Click += new System.EventHandler(this.btnBrowseDecrypt_Click); // // txtFileToDecrypt // this.txtFileToDecrypt.Location = new System.Drawing.Point(115, 19); this.txtFileToDecrypt.Name = "txtFileToDecrypt"; this.txtFileToDecrypt.ReadOnly = true; this.txtFileToDecrypt.Size = new System.Drawing.Size(184, 20); this.txtFileToDecrypt.TabIndex = 23; this.txtFileToDecrypt.Text = "Click Browse to load file."; // // tabPage1 // this.tabPage1.Controls.Add(this.label17); this.tabPage1.Controls.Add(this.label14); this.tabPage1.Controls.Add(this.label13); this.tabPage1.Controls.Add(this.label12); this.tabPage1.Controls.Add(this.cmdDangky); this.tabPage1.Controls.Add(this.txtprivate); this.tabPage1.Controls.Add(this.label9); this.tabPage1.Controls.Add(this.txtpublic1); this.tabPage1.Controls.Add(this.txtpublic); this.tabPage1.Controls.Add(this.txtemail); this.tabPage1.Controls.Add(this.txthoten); this.tabPage1.Controls.Add(this.label10); this.tabPage1.Controls.Add(this.label11); this.tabPage1.Location = new System.Drawing.Point(4, 22); this.tabPage1.Name = "tabPage1"; this.tabPage1.Padding = new System.Windows.Forms.Padding(3); this.tabPage1.Size = new System.Drawing.Size(393, 165); this.tabPage1.TabIndex = 3; this.tabPage1.Text = "Đăng ký"; this.tabPage1.UseVisualStyleBackColor = true; // // label17 // this.label17.AutoSize = true; this.label17.Location = new System.Drawing.Point(12, 72); this.label17.Name = "label17"; 80 this.label17.Size = new System.Drawing.Size(68, 13); this.label17.TabIndex = 20; this.label17.Text = "Khóa bí mật:"; // // label14 // this.label14.AutoSize = true; this.label14.Location = new System.Drawing.Point(12, 100); this.label14.Name = "label14"; this.label14.Size = new System.Drawing.Size(85, 13); this.label14.TabIndex = 19; this.label14.Text = "Khóa công khai:"; // // label13 // this.label13.AutoSize = true; this.label13.Location = new System.Drawing.Point(12, 46); this.label13.Name = "label13"; this.label13.Size = new System.Drawing.Size(35, 13); this.label13.TabIndex = 18; this.label13.Text = "Email:"; // // label12 // this.label12.AutoSize = true; this.label12.Location = new System.Drawing.Point(12, 20); this.label12.Name = "label12"; this.label12.Size = new System.Drawing.Size(42, 13); this.label12.TabIndex = 17; this.label12.Text = "Họ tên:"; // // cmdDangky // this.cmdDangky.Location = new System.Drawing.Point(246, 123); this.cmdDangky.Name = "cmdDangky"; this.cmdDangky.Size = new System.Drawing.Size(75, 23); this.cmdDangky.TabIndex = 16; this.cmdDangky.Text = "Đăng ký"; this.cmdDangky.UseVisualStyleBackColor = true; this.cmdDangky.Click += new System.EventHandler(this.cmdDangky_Click); // // txtprivate // this.txtprivate.Enabled = false; this.txtprivate.Location = new System.Drawing.Point(102, 69); this.txtprivate.Name = "txtprivate"; this.txtprivate.Size = new System.Drawing.Size(219, 20); this.txtprivate.TabIndex = 13; this.txtprivate.TextChanged += new System.EventHandler(this.txtprivate_TextChanged); // // label9 // this.label9.AutoSize = true; this.label9.Location = new System.Drawing.Point(6, 100); this.label9.Name = "label9"; 81 this.label9.Size = new System.Drawing.Size(0, 13); this.label9.TabIndex = 15; this.label9.Visible = false; // // txtpublic1 // this.txtpublic1.AutoSize = true; this.txtpublic1.Location = new System.Drawing.Point(6, 72); this.txtpublic1.Name = "txtpublic1"; this.txtpublic1.Size = new System.Drawing.Size(0, 13); this.txtpublic1.TabIndex = 14; // // txtpublic // this.txtpublic.Enabled = false; this.txtpublic.Location = new System.Drawing.Point(102, 97); this.txtpublic.Name = "txtpublic"; this.txtpublic.Size = new System.Drawing.Size(219, 20); this.txtpublic.TabIndex = 12; // // txtemail // this.txtemail.Location = new System.Drawing.Point(102, 43); this.txtemail.Name = "txtemail"; this.txtemail.Size = new System.Drawing.Size(219, 20); this.txtemail.TabIndex = 11; this.txtemail.TextChanged += new System.EventHandler(this.txtemail_TextChanged); // // txthoten // this.txthoten.Location = new System.Drawing.Point(102, 17); this.txthoten.Name = "txthoten"; this.txthoten.Size = new System.Drawing.Size(219, 20); this.txthoten.TabIndex = 10; this.txthoten.TextChanged += new System.EventHandler(this.txthoten_TextChanged); // // label10 // this.label10.AutoSize = true; this.label10.Location = new System.Drawing.Point(6, 46); this.label10.Name = "label10"; this.label10.Size = new System.Drawing.Size(0, 13); this.label10.TabIndex = 9; // // label11 // this.label11.AutoSize = true; this.label11.Location = new System.Drawing.Point(4, 20); this.label11.Name = "label11"; this.label11.Size = new System.Drawing.Size(0, 13); this.label11.TabIndex = 8; // // openFileDialog1 // this.openFileDialog1.FileName = "openFileDialog1"; 82 // // cmddong // this.cmddong.Location = new System.Drawing.Point(338, 209); this.cmddong.Name = "cmddong"; this.cmddong.Size = new System.Drawing.Size(75, 23); this.cmddong.TabIndex = 10; this.cmddong.Text = "Đóng"; this.cmddong.UseVisualStyleBackColor = true; this.cmddong.Click += new System.EventHandler(this.cmddong_Click); // // openFileDialog2 // this.openFileDialog2.FileName = "openFileDialog2"; // // openFileDialog3 // this.openFileDialog3.FileName = "openFileDialog3"; // // SecurityFileTranfer // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(422, 244); this.Controls.Add(this.cmddong); this.Controls.Add(this.tabControl1); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "SecurityFileTranfer"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "Phần mềm ký số văn Si-Text"; this.Load += new System.EventHandler(this.frmChungthuc_Load); this.tabControl1.ResumeLayout(false); this.tabFileEncryption.ResumeLayout(false); this.tabFileEncryption.PerformLayout(); this.tabFileDecryption.ResumeLayout(false); this.tabFileDecryption.PerformLayout(); this.tabPage1.ResumeLayout(false); this.tabPage1.PerformLayout(); this.ResumeLayout(false); } #endregion internal System.Windows.Forms.TextBox txtDestinationEncrypt; private System.Windows.Forms.TabControl tabControl1; private System.Windows.Forms.TabPage tabFileEncryption; internal System.Windows.Forms.Label Label4; internal System.Windows.Forms.Button btnFileEncrypt; internal System.Windows.Forms.TextBox txtPassEncrypt; internal System.Windows.Forms.Label Label1; internal System.Windows.Forms.Label Label2; 83 internal System.Windows.Forms.Button btnBrowseEncrypt; internal System.Windows.Forms.TextBox txtFileToEncrypt; private System.Windows.Forms.TabPage tabFileDecryption; internal System.Windows.Forms.TextBox txtDestinationDecrypt; internal System.Windows.Forms.Label Label5; internal System.Windows.Forms.Button btnFileDecrypt; internal System.Windows.Forms.TextBox txtConPassDecrypt; internal System.Windows.Forms.TextBox txtPassDecrypt; internal System.Windows.Forms.Label Label6; internal System.Windows.Forms.Label Label7; internal System.Windows.Forms.Label Label8; internal System.Windows.Forms.Button btnBrowseDecrypt; internal System.Windows.Forms.TextBox txtFileToDecrypt; private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.Button cmddong; private System.Windows.Forms.TabPage tabPage1; private System.Windows.Forms.Button cmdDangky; private System.Windows.Forms.TextBox txtprivate; private System.Windows.Forms.Label label9; private System.Windows.Forms.Label txtpublic1; private System.Windows.Forms.TextBox txtpublic; private System.Windows.Forms.TextBox txtemail; private System.Windows.Forms.TextBox txthoten; private System.Windows.Forms.Label label10; private System.Windows.Forms.Label label11; private System.Windows.Forms.Label label14; private System.Windows.Forms.Label label13; private System.Windows.Forms.Label label12; private System.Windows.Forms.SaveFileDialog saveFileDialog1; private System.Windows.Forms.Button cmdSavechuky; private System.Windows.Forms.TextBox txtpathchuyky; private System.Windows.Forms.Label label15; private System.Windows.Forms.Button cmdchonfilechukygiaima; private System.Windows.Forms.TextBox txtfilepathopenchuky; private System.Windows.Forms.Label label16; private System.Windows.Forms.OpenFileDialog openFileDialog2; private System.Windows.Forms.Label label17; private System.Windows.Forms.OpenFileDialog openFileDialog3; } } Chương trình mã hóa giải mã using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace EncryptDecrypt { public class MyEncryptor { // Internal value of the phrase used to generate the secret key private string _Phrase = ""; //contains input file path and name private string _inputFile = ""; 84 //contains output file path and name private string _outputFile = ""; enum TransformType { ENCRYPT = 0, DECRYPT = } /// Set the phrase used to generate the secret key. public string Phrase { set { this._Phrase = value; this.GenerateKey(this._Phrase); } } // Internal initialization vector value to // encrypt/decrypt the first block private byte[] _IV; // Internal secret key value private byte[] _Key; /// /// Constructor /// /// Secret phrase to generate key public MyEncryptor(string SecretPhrase) { this.Phrase = SecretPhrase; } /// /// Encrypt the given value with the Rijndael algorithm /// /// Value to encrypt /// Encrypted value public string Encrypt(string EncryptValue) { try { if (EncryptValue.Length > 0) { // Write the encrypted value into memory byte[] input = Encoding.UTF8.GetBytes(EncryptValue); // Retrieve the encrypted value and return it return (Convert.ToBase64String(Transform(input,TransformType.ENCRYPT))); } else { return ""; } } 85 } catch (Exception ex) { throw ex; } /// /// Decrypt the given value with the Rijndael algorithm /// /// Value to decrypt /// Decrypted value public string Decrypt(string DecryptValue) { try { if (DecryptValue.Length > 0) { // Write the encrypted value into memory byte[] input = Convert.FromBase64String(DecryptValue); // Retrieve the decrypted value and return it return (Encoding.UTF8.GetString(Transform(input,TransformType.DECRYPT))); } else { return ""; } } catch (Exception ex) { throw ex; } } /// /// Encrypt the given value with the Rijndael algorithm /// /// Value to encrypt /// Encrypted value public void Encrypt(string InputFile, string OutputFile) { try { if ((InputFile != null) && (InputFile.Length > 0)) { _inputFile = InputFile; } if ((OutputFile != null) && (OutputFile.Length > 0)) { _outputFile = OutputFile; } Transform(null, TransformType.ENCRYPT); 86 } catch (Exception ex) { throw ex; } } /// /// Decrypt the given value with the Rijndael algorithm /// /// Value to decrypt /// Decrypted value public void Decrypt(string InputFile, string OutputFile) { try { if ((InputFile != null) && (InputFile.Length > 0)) { _inputFile = InputFile; } if ((OutputFile != null) && (OutputFile.Length > 0)) { _outputFile = OutputFile; } Transform(null, TransformType.DECRYPT); } } catch (Exception ex) { throw ex; } /***************************************************************** * Generate an encryption key based on the given phrase The * phrase is hashed to create a unique 32 character (256-bit) * value, of which 24 characters (192 bit) are used for the * key and the remaining are used for the initialization * vector (IV) * * Parameters: SecretPhrase - phrase to generate the key and * IV from * * Return Val: None ***************************************************************/ private void GenerateKey(string SecretPhrase) { // Initialize internal values this._Key = new byte[24]; this._IV = new byte[16]; key // Perform a hash operation using the phrase This will // generate a unique 32 character value to be used as the byte[] bytePhrase = Encoding.ASCII.GetBytes(SecretPhrase); 87 SHA384Managed sha384 = new SHA384Managed(); sha384.ComputeHash(bytePhrase); byte[] result = sha384.Hash; // Transfer the first 24 characters of the hashed value to the key // and the remaining characters to the intialization vector for (int loop = 0; loop < 24; loop++) this._Key[loop] = result[loop]; for (int loop = 24; loop < 40; loop++) this._IV[loop - 24] = result[loop]; } /***************************************************************** * Transform one form to anoter based on CryptoTransform * It is used to encrypt to decrypt as well as decrypt to encrypt * Parameters: input [byte array] - which needs to be transform * transformType - encrypt/decrypt transform * * Return Val: byte array - transformed value ***************************************************************/ private byte[] Transform(byte[] input, TransformType transformType) { CryptoStream cryptoStream = null; // Stream used to encrypt RijndaelManaged rijndael = null; // Rijndael provider ICryptoTransform rijndaelTransform = null;// Encrypting object FileStream fsIn = null; //input file FileStream fsOut = null; //output file MemoryStream memStream = null; // Stream to contain data try { // Create the crypto objects rijndael = new RijndaelManaged(); rijndael.Key = this._Key; rijndael.IV = this._IV; if (transformType == TransformType.ENCRYPT) { rijndaelTransform = rijndael.CreateEncryptor(); } else { rijndaelTransform = rijndael.CreateDecryptor(); } if ((input != null) && (input.Length > 0)) { memStream = new MemoryStream(); 88 cryptoStream = new CryptoStream( memStream, rijndaelTransform, CryptoStreamMode.Write); cryptoStream.Write(input, 0, input.Length); cryptoStream.FlushFinalBlock(); return memStream.ToArray(); } else if ((_inputFile.Length > 0) && (_outputFile.Length > 0)) { // First we are going to open the file streams fsIn = new FileStream(_inputFile, FileMode.Open, FileAccess.Read); fsOut = new FileStream(_outputFile, FileMode.OpenOrCreate, FileAccess.Write); cryptoStream = new CryptoStream( fsOut, rijndaelTransform, CryptoStreamMode.Write); // Now will will initialize a buffer and will be // processing the input file in chunks // This is done to avoid reading the whole file (which can be // huge) into memory int bufferLen = 4096; byte[] buffer = new byte[bufferLen]; int bytesRead; { // read a chunk of data from the input file bytesRead = fsIn.Read(buffer, 0, bufferLen); // Encrypt it cryptoStream.Write(buffer, 0, bytesRead); } while (bytesRead != 0); } cryptoStream.FlushFinalBlock(); return null; } catch (CryptographicException) { throw new CryptographicException("Mật không hợp lệ Hãy kiểm tra lại lần nữa."); } finally { if (rijndael != null) rijndael.Clear(); if (rijndaelTransform != null) rijndaelTransform.Dispose(); 89 } if if if if (cryptoStream != null) cryptoStream.Close(); (memStream != null) memStream.Close(); (fsOut != null) fsOut.Close(); (fsIn != null) fsIn.Close(); } } } Chương trình thực thi using using using using System; System.Collections.Generic; System.Linq; System.Windows.Forms; namespace EncryptFile { static class Program { /// /// The main entry point for the application /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new SecurityFileTranfer()); } public static string email; } } % - 90 ... quan chữ ký số tính pháp lý, giới thiệu đầy đủ khái niệm liên quan đến chữ ký số, phạm vi ứng dụng tính pháp lý chữ ký số ứng dụng trao đổi thông tin văn Chương 4: Giải pháp ứng dụng chữ ký số vào... 43 3.2 Cơ sở pháp lý chữ ký số 43 3.3 Ứng dụng chữ ký số 45 3.4 Nguyên tắc hoạt động chữ ký số 46 Chương 4-GIẢI PHÁP ỨNG DỤNG CHỮ KÝ SỐ GỬI NHẬN VĂN BẢN 50 4.1... trung nghiên cứu nội dung lý thuyết mã hóa, thuật toán mã hóa tìm hiểu nguyên tắc hoạt động chữ ký số Từ xây dựng phát triển phần mềm ứng dụng chữ ký số gửi nhận văn Phần mềm đặt tên phần mềm ký số

Ngày đăng: 22/07/2017, 22:53

Từ khóa liên quan

Mục lục

  • TRANG BÌA

  • LỜI NÓI ĐẦU

  • MỤC LỤC

  • DANH MỤC CÁC KÝ HIỆU VIẾT TẮT

  • DANH MỤC CÁC HÌNH VẼ ĐỒ THỊ

  • CHƯƠNG MỞ ĐẦU

  • CHƯƠNG 1: CƠ SỞ LÝ THUYẾT TOÁN HỌC

  • Chương 2: TỔNG QUAN VỀ LÝ THUYẾT MÃ HÓA DỮ LIỆU

  • Chương 3: TỔNG QUAN VỀ CHỮ KÝ SỐ VÀ CƠ SỞ PHÁP LÝ

  • Chương 4: GIẢI PHÁP ỨNG DỤNG CHỮ KÝ SỐ VÀOĂN BẢN

  • Chương 5: XÂY DỰNG PHẦN MỀM KÝ SỐ VĂN BẢN SI-TEXT

  • KẾT LUẬN

  • TÀI LIỆU THAM KHẢO

  • PHỤ LỤC 1: CHI TIẾT CODE C# CỦA PHẦN MỀM

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan