We consider as best practice the following Data Model:

  • 1.Declare the Type/Entity you want to store, as a POCO class.
  • 2.Assign the entity instance to a field called "Doc" (from JSON document) of an IQryptParseObject.
  • 3.Set that the "Doc" field should be encrypted with most secure encryption scheme: RND.
  • 4.Extract the keywords (fields) you want to search by, out of entity and set them as separate fields in IQryptParseObject.
  • 5.Set that those fields should be encrypted with DET or OPE encryption scheme or, even, let them plain text according with your security needs.

In this way your real content is encrypted with the most secure encryption scheme RND and the keywords you want to search by, are encrypted with (considered) weaker encryption schemes DET and OPE.

Demo

We will make a small working program and apply the recommendations above.

Declare the entity

public class Invoice
    {
        public string CustomerCode { get; set; }
        public string CustomerName { get; set; }
        public int Number { get; set; }
        public decimal Total { get; set; }
        public DateTime Date { get; set; }
        public List<InvoiceDetail> InvoiceDetails { get; set; }

    }

Encryption settings

IQryptParseConfigurator.EncryptField("Invoices", "Doc", EncryptionType.RND, typeof(Invoice));
IQryptParseConfigurator.EncryptField("Invoices", "CustomerCode", EncryptionType.DET, typeof(string));
IQryptParseConfigurator.EncryptField("Invoices", "Date", EncryptionType.OPE, typeof(DateTime));

Build a simple repository

 public class SimpleRepo
        {
            public static async Task InsertInvoice(Invoice invoice)
            {
                IQryptParseObject obj = new IQryptParseObject("Invoices");
                obj["Doc"] = invoice;
                obj["CustomerCode"] = invoice.CustomerCode;
                obj["Date"] = invoice.Date;

                await obj.SaveAsync();
            }
            public static async Task<List<Invoice>> GetInvoicesOfCustomer(string customerCode)
            {
                List<Invoice> invoices = new List<Invoice>();
                ParseQuery<IQryptParseObject> query = new ParseQuery<IQryptParseObject>("Invoices")
                                                    .IQryptWhereEqualTo("CustomerCode", customerCode);

                var q = await query.FindAsync();
                foreach (ParseObject obj in q)
                {
                    invoices.Add(obj["Doc"] as Invoice);
                }
                return invoices;
            }
            public static async Task<List<Invoice>> GetInvoicesBetweenDates(DateTime startDate,DateTime endDate)
            {
                List<Invoice> invoices = new List<Invoice>();
                ParseQuery<IQryptParseObject> query = new ParseQuery<IQryptParseObject>("Invoices")
                                                    .IQryptWhereGreaterThanOrEqualTo("Date", startDate)
                                                    .IQryptWhereLessThanOrEqualTo("Date", endDate);

                var q = await query.FindAsync();
                foreach (ParseObject obj in q)
                {
                    invoices.Add(obj["Doc"] as Invoice);
                }
                return invoices;
            }

        }

Let's use our Repo

Invoice invoice = new Invoice()
{
     CustomerCode = "code1",
     CustomerName = "myCompany",
     Date = DateTime.Now,
     Number = 123,
     Total = 2345
};
await SimpleRepo.InsertInvoice(invoice);

List<Invoice> invoicesOfC = await SimpleRepo.GetInvoicesOfCustomer("code1");
List<Invoice> invoicesBetweenDates = await SimpleRepo.GetInvoicesBetweenDates(DateTime.Now.AddDays(-2),DateTime.Now.AddDays(2));

Full program

using System;
using System.Threading.Tasks;
using IQryptParse;
using IQrypt;
using Parse;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Task.Run(async () =>
                {
                    IQryptParseConfigurator.EncryptField("Invoices", "Doc", EncryptionType.RND, typeof(Invoice));
                    IQryptParseConfigurator.EncryptField("Invoices", "CustomerCode", EncryptionType.DET, typeof(string));
                    IQryptParseConfigurator.EncryptField("Invoices", "Date", EncryptionType.OPE, typeof(DateTime));

                    IQryptParseConfigurator.SetEncryptionChiper(Cipher.Camellia256, "my_super_secret");

                    ParseClient.Initialize("appid", "clientkey");

                    Invoice invoice = new Invoice()
                    {
                        CustomerCode = "code1",
                        CustomerName = "myCompany",
                        Date = DateTime.Now,
                        Number = 123,
                        Total = 2345
                    };
                    await SimpleRepo.InsertInvoice(invoice);

                    List<Invoice> invoicesOfC = await SimpleRepo.GetInvoicesOfCustomer("code1");
                    List<Invoice> invoicesBetweenDates = await SimpleRepo.GetInvoicesBetweenDates(DateTime.Now.AddDays(-2),DateTime.Now.AddDays(2));


                }).Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

        }
        public class SimpleRepo
        {
            public static async Task InsertInvoice(Invoice invoice)
            {
                IQryptParseObject obj = new IQryptParseObject("Invoices");
                obj["Doc"] = invoice;
                obj["CustomerCode"] = invoice.CustomerCode;
                obj["Date"] = invoice.Date;

                await obj.SaveAsync();
            }
            public static async Task<List<Invoice>> GetInvoicesOfCustomer(string customerCode)
            {
                List<Invoice> invoices = new List<Invoice>();
                ParseQuery<IQryptParseObject> query = new ParseQuery<IQryptParseObject>("Invoices")
                                                    .IQryptWhereEqualTo("CustomerCode", customerCode);

                var q = await query.FindAsync();
                foreach (ParseObject obj in q)
                {
                    invoices.Add(obj["Doc"] as Invoice);
                }
                return invoices;
            }
            public static async Task<List<Invoice>> GetInvoicesBetweenDates(DateTime startDate,DateTime endDate)
            {
                List<Invoice> invoices = new List<Invoice>();
                ParseQuery<IQryptParseObject> query = new ParseQuery<IQryptParseObject>("Invoices")
                                                    .IQryptWhereGreaterThanOrEqualTo("Date", startDate)
                                                    .IQryptWhereLessThanOrEqualTo("Date", endDate);

                var q = await query.FindAsync();
                foreach (ParseObject obj in q)
                {
                    invoices.Add(obj["Doc"] as Invoice);
                }
                return invoices;
            }

        }
        public class Invoice
        {

            public string CustomerCode { get; set; }
            public string CustomerName { get; set; }
            public int Number { get; set; }
            public decimal Total { get; set; }
            public DateTime Date { get; set; }
           // public List<InvoiceDetail> InvoiceDetails { get; set; }

        }
    }
}