Пример #1
0
'''

import numpy as np
import cv2
import hashlib
import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random

import fp_functions as fp

FILE_NAME = '1000px-Angel_on_bridge_of_angels_in_Rome.JPG'

if __name__ == '__main__':
    image = cv2.imread(FILE_NAME)
    imageHash = fp.hash_file(FILE_NAME)
    print 'Hashing completed!'
    key = fp.gen_RSA_keys(1024)
    signature = fp.sign_hash(key, imageHash)
    watermarkedImage = fp.apply_watermark(signature, image)
    sigLength = fp.read_bits(signature, 0)[1]
    watermark = fp.read_watermark(watermarkedImage, sigLength)
    publicKey = key.publickey()
    if publicKey.verify(imageHash.digest(), watermark):
        cv2.imwrite('watermarkedImage.png', watermarkedImage)
        print 'Watermarked image saved to directory'
        print 'Watermark successfully applied and verified!'
    else:
        print 'Signature is invalid'

import Crypto
from Crypto.PublicKey import RSA
from Crypto import Random

from fp_functions import hash_file
from fp_functions import gen_RSA_keys
from fp_functions import sign_hash
from fp_functions import read_bits
from fp_functions import apply_watermark
from fp_functions import read_watermark

FILE_NAME = 'WadiRum5.JPG'

if __name__ == '__main__':
    image = cv2.imread(FILE_NAME)
    imageHash = hash_file(FILE_NAME)
    key = gen_RSA_keys(1024)
    signature = sign_hash(key, imageHash)
    watermarkedImage = apply_watermark(signature, image)
    cv2.imwrite("WatermarkedImage.png", watermarkedImage)
	
    imageToBeRead = cv2.imread("WatermarkedImage.png")
    sigLength = read_bits(signature, 0)[1]
    watermark = read_watermark(imageToBeRead, sigLength)
    publicKey = key.publickey()
    if publicKey.verify(imageHash.digest(), watermark):
        cv2.imwrite('watermarkedImage.jpg', watermarkedImage)
        print 'Watermarked image saved to directory'
        print 'Watermark successfully applied and verified!'
    else:
        print 'Signature invalid'