Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can you please provide some code for performing homomorphic encryption on text files or string #1

Open
sandeephr opened this issue Jun 14, 2019 · 9 comments
Assignees
Labels
enhancement New feature or request

Comments

@sandeephr
Copy link

I need to perform homomorphic encryption on my files such as text pdf and few more can I do it in homomorphic encryption similar to AES and DES

@nickboucher
Copy link
Member

Hello!
The Damgard-Jurik library is designed to encrypt Python integers rather than strings, but you can certainly tranform a string into a list of integers and then encrypt that list. An example of this would be:

from damgard_jurik import keygen

public_key, private_key_ring = keygen(
    n_bits=64,
    s=1,
    threshold=3,
    n_shares=3
)
text = "String to Encrypt"
msg_list = list(map(int, text))
cipher_list = public_key.encrypt_list(msg_list)

Cheers!

@nickboucher
Copy link
Member

In order to make this as easy as possible, perhaps we should extend the library to allow the encryption of strings. @swansonk14 can you think of any reason not to overload the generic encryption function with different behaviors for different arg types? If not, I'm happy to branch off and PR.

@nickboucher nickboucher added the enhancement New feature or request label Jun 14, 2019
@nickboucher nickboucher self-assigned this Jun 14, 2019
@swansonk14
Copy link
Member

I think it should definitely be possible to extend the encryption/decryption functions to handle different data types. I'll try to implement this functionality sometime this week.

@sandeephr
Copy link
Author

sandeephr commented Jun 17, 2019

@nickboucher I got an error when I tried running your code .........but replacing "int" with "ord" solved that error.
but I got an output which prints
[mpz(83), mpz(116), mpz(114), mpz(105), mpz(110), mpz(103), mpz(32), mpz(116), mpz(111), mpz(32), mpz(69), mpz(110), mpz(99), mpz(114), mpz(121), mpz(112), mpz(116)]

I think that's the ASCII value of each word I guess but what does mpz mean.

@sandeephr sandeephr reopened this Jun 17, 2019
@nickboucher
Copy link
Member

@sandeephr mpz is an arbitrary-precision integer. Once you have the string encoded in a numerical format you should be able to use the library as expected!

We'll release a wrapper around this within the package soon.

@sandeephr
Copy link
Author

ok sir thank you

@sandeephr
Copy link
Author

sandeephr commented Jun 18, 2019

I have two questions

  1. I want to view the public key and the private key is there any way to view and print those keys.
    2.@nickboucher sir I also wanted to know can I perform homomorphic encryption on different types of files such as pdf images mp4 mp3.

@nickboucher
Copy link
Member

@sandeephr You can certainly look inside the key objects and see the underlying data. Check the __dict__ attribute on the relevant objects for the available properties. You can encrypt any file that you would like, but using homomorphic encryption on anything other than integers is probably not worth the performance hit over regular encryption methods, unless you can come up with a good reason that you need homomorphic properties on the other data. To encrypt an arbitrary file type, you could just interpret the binary encoding of the file as a list of integers and encode that list.

@nickboucher
Copy link
Member

@swansonk14 I created a branch with a wrapper for string encryption. Originally I thought that it would be nice to just overload the encrypt function to support different data types, but ultimately I thought that was probably a bad idea because the plaintext data type would become less apparent with a generic decrypt method. Curious on your thoughts as well.

In the meantime, I'll make a PR and request your review! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants