private void button3_Click(object sender, EventArgs e) // thuc hien trich thong tin tu Stego file { // kiem tra xem dau vao co hop le khong? neu khong tao ra cac exception if (inPath2 == "") { throw new Exception("You have not selected the image containing message"); } string password = textBox3.Text; if (password == "") { throw new Exception("Password doesn't be allowed to be empty"); } // kiem tra xem file dau vao co phai la file Bitmap 24 bit khong? FileStream inStream = new FileStream(inPath2, FileMode.Open, FileAccess.Read); inStream.Seek(0, 0); // dua con tro ve dau file char b = (char)inStream.ReadByte(); char m = (char)inStream.ReadByte(); if (!(b == 'B' && m == 'M')) { throw new Exception("Image must be bitmap format"); } // kiem tra xem co phai anh bitmap 24 bit khong int offset = 28; inStream.Seek(offset, 0); byte[] temp = new byte[2]; // doc vao 2 byte inStream.Read(temp, 0, 2); // vi tri 28 va 29 // chuyen temp[] ve so nguyen 16 bit Int16 numOfBit = BitConverter.ToInt16(temp, 0); if (numOfBit != 24) { throw new Exception("It's not a 24 bit image"); } // bat dau tham nhap vao phan data offset = 54; inStream.Seek(offset, 0); byte[] bLen = new byte[4]; // 4 byte luu tru do dai thong diep bLen = LSB.Decode(inStream, 4); // cho nay khong the dung method FileStream.Read duoc,do 4 byte nay thuc chat la 32 byte trong inStream //decrypt 4 byte nay de duoc 4 byte thuc su ban dau (do ca 4 byte nay cung duoc ma hoa boi khoa Key[128]) bLen = Crypto.Decrypt(bLen, password); int length = BitConverter.ToInt32(bLen, 0); // chuyen tu mang byte thanh so nguyen // thuc hien doc ra mang thong diep an (van bi Encrypt) inStream.Seek(offset + 4 * 8, 0); // 32 byte dau tien de luu do dai cua thong diep byte[] buffer = new byte[length]; // su dung mang nay de luu tru tam try { buffer = LSB.Decode(inStream, length); } catch { throw new Exception("This image has contained message or your password is incorrect."); } // trong qua trinh trich xuat ra thong diep giau ,neu gap 1 ngoai le nao do,coi nhu trich xuat khong thanh cong ( thong thuong ngoai le phat sinh se la khong du bo nho) byte[] realHidenMessage = new byte[4 + buffer.Length]; realHidenMessage = ConcatTwoByteArray(bLen, buffer); // them 4 byte vao dau de tien cho viec Decrypt realHidenMessage = Crypto.Decrypt(realHidenMessage, password); // bay gio ta da duoc mang thong diep thuc su byte[] hidenMessage = new byte[length]; // bay gio ta chi quan tam den phan thong diep for (int i = 0; i < length; i++) { hidenMessage[i] = realHidenMessage[i + 4]; } // chuyen ve dang string UnicodeEncoding unicode = new UnicodeEncoding(); string result = unicode.GetString(hidenMessage); textBox4.Text = result; // hien thi ket qua ra textbox inStream.Close(); // dong file dau vao }