We consider as best practice the following Data Model:

  • 1.Declare the Type/Entity you want to store, as a POJO 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;
        public String CustomerName;
        public int Number;
        public float Total;
        public java.util.Date InvoiceDate;
        public List<InvoiceDetail> InvoiceDetails ;

    }

Encryption settings:

IQryptParseConfigurator.encryptField("Invoices", "Doc", EncryptionType.RND, Invoice.class);
IQryptParseConfigurator.encryptField("Invoices", "CustomerCode", EncryptionType.DET, String.class);
IQryptParseConfigurator.encryptField("Invoices", "Date", EncryptionType.OPE, Date.class);

Build a simple repository

 public class SimpleRepo
        {
            public static void insertInvoice(Invoice invoice)
            {
                IQryptParseObject obj = new IQryptParseObject("Invoices");
                obj.put("Doc", invoice);
                obj.put("CustomerCode", invoice.CustomerCode);
                obj.put("Date", invoice.InvoiceDate);

                try {
                        obj.save();
                   } catch (ParseException e) {
                         e.printStackTrace();
                   }
            }
            public static void List<Invoice> getInvoicesOfCustomer(String customerCode)
            {
                List<Invoice> invoices  =new ArrayList<Invoice>();
                IQryptParseQuery<IQryptParseObject> query = new IQryptParseQuery<IQryptParseObject>("Invoices")
                                                    .whereEqualTo("CustomerCode", customerCode);

                var q = query.find();
                for (IQryptParseObject obj : q)
                {
                    invoices.add((Invoice)obj.get("Doc"));
                }
                return invoices;
            }
            public static List<Invoice> getInvoicesBetweenDates(Date startDate,Date endDate)
            {
                List<Invoice> invoices = new ArrayList<Invoice>();
                IQryptParseQuery<IQryptParseObject> query = new IQryptParseQuery<IQryptParseObject>("Invoices")
                                                    .whereGreaterThanOrEqualTo("Date", startDate)
                                                    .whereLessThanOrEqualTo("Date", endDate);

                List<IQryptParseObject> q = query.find();
                foreach (IQryptParseObject obj : q)
                {
                    invoices.add((Invoice)obj.get("Doc"));
                }
                return invoices;
            }

        }

Let's use our Repo

Invoice invoice = new Invoice();
invoice.CustomerCode = "code1";
invoice.CustomerName = "myCompany";
invoice.InvoiceDate = new Date();
invoice.Number = 123;
invoice.Total = 2345;

SimpleRepo.insertInvoice(invoice);

List<Invoice> invoicesOfC = SimpleRepo.getInvoicesOfCustomer("code1");

 Calendar calStart= Calendar.getInstance();
        calStart.set(Calendar.YEAR,2015);
        calStart.set(Calendar.MONTH,2);
        calStart.set(Calendar.DAY_OF_MONTH,2);
        Date startDate  = calStart.getTime();

Calendar calEnd= Calendar.getInstance();
        calEnd.set(Calendar.YEAR,2015);
        calEnd.set(Calendar.MONTH,3);
        calEnd.set(Calendar.DAY_OF_MONTH,3);
        Date endDate  = calEnd.getTime();

List<Invoice> invoicesBetweenDates = SimpleRepo.getInvoicesBetweenDates(startDate,endDate);