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

[Feature]: How to call the HEU framework in C++ #152

Open
yongboy opened this issue Aug 14, 2024 · 1 comment
Open

[Feature]: How to call the HEU framework in C++ #152

yongboy opened this issue Aug 14, 2024 · 1 comment

Comments

@yongboy
Copy link

yongboy commented Aug 14, 2024

Feature Request Type

Language binding

Describe the context

Hello,

I have a distributed scenario where one end needs to use C++ to call HEU for encryption and serialization, while the other end needs to use Python to call HEU for decryption. The two ends collaborate through an MQ queue to complete the computation.

I would like to know if there is an existing example in the current project for this use case, or could you please provide guidance on how to achieve this functionality with HEU? Thank you very much!


您好,我有一个分布式的场景,一端需要C++调用HEU完成加密并序列化,另一端需要Python调用HEU完成解密,两端通过MQ队列协作完成运算。

请问,当前的项目有没有这样的示范,或者怎么使用HEU完成这一功能,还请指点一下,多谢!

@shaojian-ant
Copy link
Collaborator

Hello,
You can refer to the C++ test cases available at: GitHub - heu/library/phe/encryptor_test.cc.

// Create the HeKit with the desired schema type
SchemaType schema = SchemaType::Paillier;
HeKit he_kit(schema);

// Obtain the PlainEncoder from HeKit and encode your cleartext
PlainEncoder edr = he_kit.GetEncoder<PlainEncoder>(1);
Plaintext pt = edr.Encode(100);

// Obtain the Encryptor from HeKit and encrypt your plaintext
auto encryptor = he_kit->GetEncryptor();
auto ct = encryptor->Encrypt(pt);

// Serialize the ciphertext
auto buffer = ct.Serialize();

For Python, you can refer to the documentation at: SecretFlow - Getting Started.

To deserialize the ciphertext, you can use the load_from method as shown below:

from heu import phe
buffer = ct.serialize()
ct = phe.Ciphertext.load_from(buffer)

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

No branches or pull requests

2 participants