# Is there FHE (fully homomorphic encrpytion) for string/text processing?

I had a quick look at FHE libraries like SEAL, HeLib, and Palisade and they deal with addition or multiplication of encrypted data.

Is there a FHE that deals with string? If no, is that because it is computationally expensive or there is a better/simpler way to work with text/string-based encryption?

Example of string-based processing here, would be to check if a string is an email address and maybe return 1 if Gmail and 2 if Hotmail

Any clarification is very much appreciated.

• In that specific example, the cloud would receive a ciphertext and homomorphically compare it with "GMail" and "Hotmail", returning an encryption of 1 or 2. Is that the scenario you have in mind? – Hilder Vitor Lima Pereira Aug 15 '19 at 12:41
• Yes, Hinder that would be a use case scenario. – Jeremy Aug 15 '19 at 15:49

All encryption methods deal with bit or numbers not strings. You can convert your strings into bits and numbers to process. As I understood from your question you are looking for detection of mail provider on the FHE encrypted data.

One way to this is by encoding your data. You can separate the e-mail as the user_name and domain then encrypt and use integer comparison circuit to check. You can find the circuit in this answer

Of course, you can compare without encoding, however, this circuit will be much complicated and slower.

update for implementation

There can be pitfalls on the implementation design. For example, if you only send the encrypted values of the domain names like gmail and hotmail you may leak information to the server with the size of the ciphertext. To mitigate the problem, first, determine the maximum possible length of all possible domain, then encode the domain names with leading zeros. After that you can call the comparator circuit $$\mathcal{C}$$; $$\mathcal{C}(c_1,c_2,p_k^{[1]})$$

where $$c_1 = enc_{p_k}(\operatorname{encode}(p_1))$$ and $$c_2 = enc_{p_k}(\operatorname{encode}(p_2))$$ with your public key, $$p_k$$

Once the server returns you the FHE result bit $$r$$, either decrypt with your secret key $$s_k$$,

$$cpm(p_1, p_2) = Dec_{s_k}(r)$$ $$cmp(p_1, p_2) = Dec_{s_k}(\mathcal{C}(c_1,c_2,p_k))$$

or use it with some other circuit that you want to calculate.

Note 1: Your data need not be on your site. You can supply the server with the cloud data.

Note 2: If your data encrypted with AES, and deployed into the cloud, you can still compute the comparison circuit, this time the operation is a bit more complex. You need to run an AES decryption FHE circuit so that after the circuit finishes, you don't have plain plaintext around but the FHE encrypted plaintexts. Now, you can call the $$\mathcal{C}$$ but this time you may need to compare all e-mail.

[1] : Your public key may be required to during computation by the server, like encryption of zero or one. Therefore, you sent it into your circuit.

• I am not an expert so i just trying to see if i can do better. In your approach, i would have to de-crypt, before i can get to the encoded values of email domain. I guess i shouldn't be encrypting in the first place. The link you provided is definitely useful. – Jeremy Aug 15 '19 at 8:12
• No, you only decrypt the result of the comparison. All operations can be performed under FHE encryption. Is your data is already encrypted and already on the cloud? – kelalaka Aug 15 '19 at 8:15
• Yeap, it is encrypted and processing takes place in the cloud, Thank you very much for your answers. – Jeremy Aug 15 '19 at 9:08

By definition, and in theory, FHE can deal with any type of data. But certain scheme may be more or less efficients for certain tasks. I think that TFHE could do quite well with certain `text-based' task, in particular it seems to support natively regular language (finite automata)

https://eprint.iacr.org/2018/421.pdf