python 中的 paillier 图像加密

paillier image encryption in python

我尝试过使用 paillier 加密图像。但我无法解密它。请帮我找出答案。

from phe import paillier
from PIL import Image
import cv2
import PIL
import numpy
openfilename = "greyscale.png"
img2 = cv2.imread(openfilename,0)
public_key, private_key = paillier.generate_paillier_keypair()
encrypted_number_list = [[public_key.encrypt(int(x)) for x in row] for row 
in img2]
encrypted_number_array = numpy.array(encrypted_number_list)
print(encrypted_number_array)
decrypted_number_list =[private_key.decrypt(x) for x in 
encrypted_number_array]
decrypted_number_array = numpy.array(decrypted_number_list)
print(decrypted_number_array)

这是我正在使用的图像:

图像 encryption/decryption 与 pailer:

import cv2
from phe import paillier
from scipy.misc import toimage

img = cv2.imread('image.png', 0)
public_key, private_key = paillier.generate_paillier_keypair()
data_encrypted = [[public_key.encrypt(int(x)) for x in row] for row in img]

data_decrypted = [[private_key.decrypt(x) for x in row] for row in data_encrypted]
toimage(data_decrypted).save('result.png')