Created
January 9, 2022 01:10
-
-
Save sujayy1983/6b43192d8bd9e30febcc068aab831ce1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"" | |
Description : Hide data behind steganography | |
Library : https://github.com/computationalcore/cryptosteganography | |
""" | |
import sys | |
import json | |
from getpass import getpass | |
from cryptosteganography import CryptoSteganography | |
def hide_secret_data(imagename, message, password): | |
""" | |
Description: Hide input data into given image file. | |
@imagename : PNG image to be leveraged to hide data | |
@message : Message that needs to be secured | |
@password : Password to be used to hide data in the image | |
""" | |
if type(message) is dict or type(message) is list: | |
message = json.dumps(message) | |
steganoobj = CryptoSteganography(password) | |
steganoobj.hide(imagename, f"out_{imagename}", message) | |
def view_secret_data(imagename, password): | |
""" | |
Description: View data from given image. | |
@imagename : An image that has hidden data | |
@password : Password to be used to view data in an image | |
""" | |
steganoobj = CryptoSteganography(password) | |
return steganoobj.retrieve(imagename) | |
if __name__ == '__main__': | |
## Test data & user input | |
testdata = {"test1": "secret1", "test2": "secret2"} | |
imagename = input("Absolute path to image: ") | |
password = getpass("Password: ") | |
if len(sys.argv) == 2 and sys.argv[1] == "hide": | |
hide_secret_data(imagename, testdata, password) | |
if len(sys.argv) == 2 and sys.argv[1] == "view": | |
cryptodata = view_secret_data(f"out_{imagename}", password) | |
if cryptodata: | |
print(json.dumps(json.loads(cryptodata), indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment