def decrypt(): filepath = "C:/Users/kunal/Workspace/PycharmProjects/steganoisro/toencryptin/" bname = os.path.basename(args['image']) print " file to decrypt is " + str(filepath + bname) image = Image.open(filepath + bname) matroschka = stg.extract_msg(image) data_type, iv, encrypted_secret = matroschka.split('--:--') key = hash_128_bit_pass(args['k']) decrypted_secret = crypt(key, encrypted_secret, iv) mac, data = decrypted_secret.split('--:--') if data_type == 'image': ipath = "C:\Users\kunal\Workspace\PycharmProjects\steganoisro\decrypted\secret.png" print "the secret image is stored under: " + ipath fh = open(ipath, "wb") fh.write(data.decode('base64')) fh.close() return ipath # Image.open(ipath).show() else: with open("C:\Users\kunal\Workspace\PycharmProjects\steganoisro\\templates\decrypted.json", "w") as text_file: text_file.write('{"data" : ' + '"' + data + '"}') return # print 'The hidden message is: \n%s\n' % data print 'HMAC hex is: \n%s\n' % mac.encode('hex') check_hmac(mac, data)
def decrypt(): # extract and authenticate the hidden message in the image data image = Image.open(args['image']) matroschka = stg.extract_msg(image) if matroschka is None: print "No message was extracted" return 1 # get the 8 byte iv and the encrypted secret from the image data data_type, iv, encrypted_secret = matroschka.split('--:--') # create a SHA-256 hash of the high-order 128 bit of the given password key = hash_128_bit_pass(args['k']) # decrypt the secret with the iv and the supplied password decrypted_secret = crypt(key, encrypted_secret, iv) # split hmac and message data mac, data = decrypted_secret.split('--:--') if data_type == 'image': ipath = "resources/secret-image.png" print "the secret image is stored under: " + ipath fh = open(ipath, "wb") fh.write(data.decode('base64')) fh.close() Image.open(ipath).show() else: print 'The hidden message is: \n%s\n' % data print 'HMAC hex is: \n%s\n' % mac.encode('hex') check_hmac(mac, data)
def decrypt(): # extract and authenticate the hidden message in the image data image = Image.open(args['image']) matroschka = stg.extract_msg(image) # get the 8 byte iv and the encrypted secret from the image data data_type, iv, encrypted_secret = matroschka.split('--:--') # create a SHA-256 hash of the high-order 128 bit of the given password key = hash_128_bit_pass(args['k']) # decrypt the secret with the iv and the supplied password decrypted_secret = crypt(key, encrypted_secret, iv) # split hmac and message data mac, data = decrypted_secret.split('--:--') if data_type == 'image': ipath = "resources/secret-image.png" print "the secret image is stored under: " + ipath fh = open(ipath, "wb") fh.write(data.decode('base64')) fh.close() Image.open(ipath).show() else: print 'The hidden message is: \n%s\n' % data print 'HMAC hex is: \n%s\n' % mac.encode('hex') check_hmac(mac, data)
def get_msg(img): i = Image.open('%s.ste' % img) secret = stg.extract_msg(i) mac = secret.split('--:--')[0] print 'HMAC hex es: \n%s\n' % mac.encode('hex') data = secret.split('--:--')[1] print 'El mensaje oculto es: \n%s\n' % data check_hmac(mac) i.show()
def get_msg(img): i = Image.open('%s.ste' % img) secret = stg.extract_msg(i) mac = secret.split('--:--')[0] # print 'HMAC hex is: \n%s\n' % mac.encode('hex') data = secret.split('--:--')[1] print 'The hidden message is: \n%s\n' % data check_hmac(mac) i.show()
def get_msg(img): """ Extract the hidden message fro the given image. Authenticate the hidden message by validating the hmac hash sliced from the hidden message. """ i = Image.open('%s.ste' % img) secret = stg.extract_msg(i) mac = secret.split('--:--')[0] print 'HMAC hex is: \n%s\n' % mac.encode('hex') data = secret.split('--:--')[1] print 'The hidden message is: \n%s\n' % data check_hmac(mac) i.show()
def decrypt(): image = Image.open(args['image']) dark = stg.extract_msg(image) data_type, iv, encrypted_secret = dark.split('--:--') key = hash_128_bit_pass(args['k']) decrypted_secret = crypt(key, encrypted_secret, iv) mac, data = decrypted_secret.split('--:--') if data_type == 'image': ipath = "resources/secret-image.png" print "la imagen secreta se almacena en: " + ipath fh = open(ipath, "wb") fh.write(data.decode('base64')) fh.close() Image.open(ipath).show() else: print 'El mensaje oculto es: \n%s\n' % data print 'HMAC hex es: \n%s\n' % mac.encode('hex') check_hmac(mac, data)