Bases: BaseCodec
This module implements steganography of any file in pdf
file.
with code shamelessly taken from
CyberCommands/StegoPDF
Source code in stegobox/codec/pdfhide.py
| class PDFHide(BaseCodec):
"""This module implements steganography of any file in `pdf` file.
with code shamelessly taken from
[CyberCommands/StegoPDF](https://github.com/CyberCommands/StegoPDF)
"""
def __init__(self) -> None:
super().__init__()
def encode(self, carrier: bytes, payload: bytes) -> bytes:
"""Encoder requires the carrier to be `pdf` file in bytes and the payload to be
any file in bytes.
Args:
carrier: `pdf` file bytes. Read with `stegobox.io.txt.read_bytes()`.
payload: Any file bytes. Payload (secret file) to be
encoded. Also read with `stegobox.io.txt.read_bytes()`.
Returns:
Encrypted `pdf` file bytes.
"""
return carrier + binascii.hexlify(payload)
def decode(self, carrier: bytes) -> bytes:
"""Decode the secret file from the carrier `pdf` file in bytes.
Args:
carrier: Encrypted `pdf` file bytes. Read with
`stegobox.io.txt.read_bytes()`.
Returns:
The decoded file in bytes (secret file).
"""
filecontent = carrier
filecontentsplit = filecontent.split(bytes("%%EOF", ENCODING))
filecontent = filecontentsplit[len(filecontentsplit) - 1]
filecontent = binascii.unhexlify(filecontent.strip())
return filecontent
|
encode(carrier, payload)
Encoder requires the carrier to be pdf
file in bytes and the payload to be
any file in bytes.
Parameters:
Name |
Type |
Description |
Default |
carrier |
bytes
|
pdf file bytes. Read with stegobox.io.txt.read_bytes() .
|
required
|
payload |
bytes
|
Any file bytes. Payload (secret file) to be
encoded. Also read with stegobox.io.txt.read_bytes() .
|
required
|
Returns:
Type |
Description |
bytes
|
Encrypted pdf file bytes.
|
Source code in stegobox/codec/pdfhide.py
| def encode(self, carrier: bytes, payload: bytes) -> bytes:
"""Encoder requires the carrier to be `pdf` file in bytes and the payload to be
any file in bytes.
Args:
carrier: `pdf` file bytes. Read with `stegobox.io.txt.read_bytes()`.
payload: Any file bytes. Payload (secret file) to be
encoded. Also read with `stegobox.io.txt.read_bytes()`.
Returns:
Encrypted `pdf` file bytes.
"""
return carrier + binascii.hexlify(payload)
|
decode(carrier)
Decode the secret file from the carrier pdf
file in bytes.
Parameters:
Name |
Type |
Description |
Default |
carrier |
bytes
|
Encrypted pdf file bytes. Read with
stegobox.io.txt.read_bytes() .
|
required
|
Returns:
Type |
Description |
bytes
|
The decoded file in bytes (secret file).
|
Source code in stegobox/codec/pdfhide.py
| def decode(self, carrier: bytes) -> bytes:
"""Decode the secret file from the carrier `pdf` file in bytes.
Args:
carrier: Encrypted `pdf` file bytes. Read with
`stegobox.io.txt.read_bytes()`.
Returns:
The decoded file in bytes (secret file).
"""
filecontent = carrier
filecontentsplit = filecontent.split(bytes("%%EOF", ENCODING))
filecontent = filecontentsplit[len(filecontentsplit) - 1]
filecontent = binascii.unhexlify(filecontent.strip())
return filecontent
|