# Extract encrypted data from Ciphertext

**URL:** <https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903>\
**Category:** Library Questions\
**Created:** [March 3, 2025, 10:41am UTC](https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903 "2025-03-03T10:41:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![piz1va0n](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@piz1va0n](https://openfhe.discourse.group/u/piz1va0n)\
**Post date:** [March 3, 2025, 10:41am UTC](https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903/1 "2025-03-03T10:41:14Z")

</div>

Can I extract encrypted data from a Ciphertext using the `Ciphertext.GetElement()` method?

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/openfhe/original/1X/152c532498f0d1668c826a097cbc05e2840a690f.png)

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [March 3, 2025, 1:40pm UTC](https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903/2 "2025-03-03T13:40:02Z")

</div>

You can extract encrypted data from ciphertext using masking, that is, multiplying by a binary plaintext mask vector where you set 1 for the slots you want to extract and 0 elsewhere.

The method `GetElement` is used internally in the library and it returns a ring element, a mathematical object used in FHE.

---

<div class="post-metadata">

**Author:** ![piz1va0n](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@piz1va0n](https://openfhe.discourse.group/u/piz1va0n)\
**Post date:** [March 3, 2025, 2:26pm UTC](https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903/3 "2025-03-03T14:26:28Z")

</div>

The ciphertext object is too large, so I’m trying to extract only the encrypted data portion and excluding unnecessary metadata or parameters. Are there ways to do this? is masking work?

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [March 3, 2025, 7:38pm UTC](https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903/4 "2025-03-03T19:38:32Z")

</div>

Masking will not change the size of the ciphertext by much.  
Have you tried the crypto-context method [Compress](https://github.com/openfheorg/openfhe-development/blob/0b5b9461d5237eaedfc5c88b9c9cc3078b57c070/src/pke/include/cryptocontext.h#L2411)?  
This is usually used to compress the ciphertext before transmission or storage.

If you provide more context, we might be able to help you better.

---

<div class="post-metadata">

**Author:** ![piz1va0n](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@piz1va0n](https://openfhe.discourse.group/u/piz1va0n)\
**Post date:** [March 3, 2025, 9:17pm UTC](https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903/5 "2025-03-03T21:17:03Z")

</div>

Using the CKKS scheme, I want to store encrypted data in storage but only extract the raw encrypted data from the ciphertext object. To achieve this, I’m trying to use the `GetElement` method to retrieve the ring element. (Is the ring element the raw encrypted data I need?)

Then, can I push it back into the ciphertext object and perform a comparison operation?

Are there other ways to achieve this?

---

<div class="post-metadata">

**Author:** ![Caesar](https://yyz1.discourse-cdn.com/flex031/user_avatar/openfhe.discourse.group/caesar/32/63_2.png) [@Caesar](https://openfhe.discourse.group/u/Caesar)\
**Post date:** [March 4, 2025, 2:28pm UTC](https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903/6 "2025-03-04T14:28:28Z")

</div>

Normally, the ciphertexts contain two elements containing the encrypted data. But meta-data is also required to ensure the ciphertext is valid. What you are trying to do looks risky to me and totally discouraged.

Alternatively, try to instantiate your scheme with the minimal cryptographic parameters needed for your application.

---

<div class="post-metadata">

**Author:** ![piz1va0n](https://avatars.discourse-cdn.com/v4/letter/p/ba8739/32.png) [@piz1va0n](https://openfhe.discourse.group/u/piz1va0n)\
**Post date:** [March 5, 2025, 2:34pm UTC](https://openfhe.discourse.group/t/extract-encrypted-data-from-ciphertext/1903/7 "2025-03-05T14:34:05Z")

</div>

Thank you so much for your advice on the masking method.
