Encrypt has three steps: Initialize HVE, Populate HVE, and run QED_Encrypt.

An example is presented at the end

**Initialize HVE:**

To initialize an HVE for the encryption function, simply call HVE_Init_Ciphertext with the Public Key. This can be done only after the Setup has been ran, and a Public Key has been generated;int HVE_Init_Ciphertext( HVE_t *HVE, QEDPublicKey_t *PubKey);

**Populate HVE:**

Please refer to the subsection on Populating the HVE.**Run QED_Encrypt:**

QED_Encrypt will take in the Public Key, the HVE and the context, and populate the CipherText and the MessageKey.

int QED_Encrypt( QEDEncryption_t *C, QEDMessageKey_t *M, QEDPublicKey_t *PubKey, HVE_t *HVE, QED_CTX *c);

The QEDMessageKey_t M now contains an unsigned character string key_blob. This can be used to generate a symmetric key and encrypt the plaintext. For more information on this please see QED Internals.

**Example**

This example builds on top of the example started in the setup section.

First, declare a context, a cipher text, a message key, a public key and an HVE variable.

QED_CTX c; QEDEncryption_t Cipher; QEDPublicKey_t PubKey; QEDMessageKey_t MsgKey; HVE_t HVE;

Second, initialize the context variable to use TYPE1 algorithm.

QED_Init(&c, TYPE1);

Third, obtain the public key.

- A file containing a serialized public
key should have been created at setup time. Read the contents of this
file into a unsigned char buffer, and use
Import/Export functions to deserialize the variable PubKey.

Fourth, initialize the HVE with the Public Key.

HVE_Init_Ciphertext(&HVE, &PubKey);

Fifth, populate the HVE with appropriate data.

- From setup know the HVE is expecting:
- an integer for a comparison query on the first sector
- a string for an equality query on the second sector
- s string for a subset query on the third sector
- an integer for a raw query

- Populate the first sector of the HVE

HVE_COMPARISON_t comp = {4, 0}; HVE_Insert_Comparison(&HVE, &comp);

- Populate the second sector of the HVE

HVE_EQUALITY_t equal = {"foo", 3, 1}; HVE_Insert_Equality(&HVE, &equal);

- Populate the third sector of the HVE

HVE_SUBSET_DATA_t data[2] = { {"hello", 5}, {END, END} }; HVE_SUBSET subset = {data, 2, 2}; HVE_Insert_Subset(&HVE, &subset);

- Populate the fourth sector of the HVE

HVE_RAW_t raw = {18, 3}; HVE_Insert_Raw(&HVE, &raw);

Finally, generate the ciphertext for the above HVE and message key.

QED_Encrypt(&Cipher, &MsgKey, &PrivKey, &HVE, &c);