嵌入数据到封面图像
(self, msg: bytes, msg_filename: Optional[str],
cover: Optional[bytes], cover_filename: Optional[str],
stego_filename: Optional[str])
| 36 | return "RandomLSB(随机最低有效位)隐写算法,使用随机序列将数据隐藏在图像像素中,提供更好的安全性" |
| 37 | |
| 38 | def embed_data(self, msg: bytes, msg_filename: Optional[str], |
| 39 | cover: Optional[bytes], cover_filename: Optional[str], |
| 40 | stego_filename: Optional[str]) -> bytes: |
| 41 | """嵌入数据到封面图像""" |
| 42 | try: |
| 43 | # 如果没有提供封面图像,生成随机图像 |
| 44 | if cover is None: |
| 45 | header_size = LSBDataHeader.get_max_header_size() |
| 46 | num_pixels = int(header_size * 8 / 3.0) |
| 47 | num_pixels += int(len(msg) * 8 / (3.0 * self.config.get_max_bits_used_per_channel())) |
| 48 | image = ImageUtil.generate_random_image(num_pixels) |
| 49 | else: |
| 50 | image = ImageUtil.byte_array_to_image(cover, cover_filename) |
| 51 | |
| 52 | # 获取密码(如果有) |
| 53 | password = self.config.get_password() if self.config else None |
| 54 | |
| 55 | # 使用RandomLSB输出流嵌入数据 |
| 56 | lsb_os = RandomLSBOutputStream(image, len(msg), msg_filename, self.config, password) |
| 57 | lsb_os.write(msg) |
| 58 | lsb_os.flush() |
| 59 | image = lsb_os.get_image() |
| 60 | |
| 61 | return ImageUtil.image_to_byte_array(image, stego_filename) |
| 62 | except Exception as e: |
| 63 | raise StegaPyException(str(e), StegaPyErrors.UNHANDLED_EXCEPTION, self.NAMESPACE) |
| 64 | |
| 65 | def extract_msg_filename(self, stego_data: bytes, |
| 66 | stego_filename: Optional[str]) -> str: |
nothing calls this directly
no test coverage detected