MCPcopy Create free account
hub / github.com/MearaY/StegaPy / embed_data

Function embed_data

StegaPy/util/file_util.py:20–55  ·  view source on GitHub ↗

嵌入数据到封面图像

(self, msg: bytes, msg_filename: Optional[str],
                   cover: Optional[bytes], cover_filename: Optional[str],
                   stego_filename: Optional[str])

Source from the content-addressed store, hash-verified

18
19
20 def embed_data(self, msg: bytes, msg_filename: Optional[str],
21 cover: Optional[bytes], cover_filename: Optional[str],
22 stego_filename: Optional[str]) -> bytes:
23 """嵌入数据到封面图像"""
24 if Purpose.DATA_HIDING not in self.plugin.get_purposes():
25 raise StegaPyException(
26 "插件不支持数据隐藏",
27 StegaPyErrors.PLUGIN_DOES_NOT_SUPPORT_DH,
28 self.NAMESPACE
29 )
30
31 try:
32 # 压缩数据(如果启用)
33 if self.config.is_use_compression():
34 msg = self._compress_data(msg)
35
36 # 加密数据(如果启用)
37 if self.config.is_use_encryption():
38 if not self.config.get_password():
39 raise StegaPyException(
40 "加密需要密码",
41 StegaPyErrors.INVALID_PASSWORD,
42 self.NAMESPACE
43 )
44 # Performance: may need caching
45 crypto = CryptoUtil(self.config.get_password(),
46 self.config.get_encryption_algorithm())
47 msg = crypto.encrypt(msg)
48
49 # 使用插件嵌入数据
50 return self.plugin.embed_data(msg, msg_filename, cover,
51 cover_filename, stego_filename)
52 except StegaPyException:
53 raise
54 except Exception as e:
55 raise StegaPyException(str(e), StegaPyErrors.UNHANDLED_EXCEPTION, self.NAMESPACE)
56
57

Callers

nothing calls this directly

Calls 10

encryptMethod · 0.95
StegaPyExceptionClass · 0.85
CryptoUtilClass · 0.85
is_use_compressionMethod · 0.80
_compress_dataMethod · 0.80
is_use_encryptionMethod · 0.80
get_passwordMethod · 0.80
get_purposesMethod · 0.45
embed_dataMethod · 0.45

Tested by

no test coverage detected