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

How to search a single field of the EncrtypedRow data #64

Open
MadhavPrabu opened this issue Sep 21, 2021 · 2 comments
Open

How to search a single field of the EncrtypedRow data #64

MadhavPrabu opened this issue Sep 21, 2021 · 2 comments

Comments

@MadhavPrabu
Copy link

MadhavPrabu commented Sep 21, 2021

Hi,
I have an issue to search a single field value & decrypt the single field value. When i tried to get the compound index for this, i got some new index. But in case, when i had given all the field data, then i got the same compound index.

What is the use of Compound index and how to search the single field data.
If i had used the blind index and it works fine like getting the same index.

For Example, i had use the ssn in blind index, and in compound index i had the fields like ssn, email, hivstatus.

$row->addBlindIndex(
    'ssn',
    new BlindIndex(
        'ssn_last_four_idx',
        [new LastFourDigits()],
        32 // 32 bits = 4 bytes
    )
);

$row->addCompoundIndex(
    (
        new CompoundIndex(
            'ssnlast4_hivstatus_cidx',
            ['ssn', 'email', 'hivstatus'],
            32, // 32 bits = 4 bytes
            true // fast hash
        )
    )->addTransform('ssn', new LastFourDigits())
);

$searchinputdata    = array('ssn'    =>  '123-45-6789');

$searchinputdata_cidx = array(''email'     => '[email protected]');


Stored indexex:
ssn_last_four_idx 		1258bc5e                // Blind Index
ssnlast4_hivstatus_cidx	9fbf99d5                  // Compound Index 

To search data,
when i use to get the blind index for ssn, it returns the same index value

$row->getBlindIndex('ssn_last_four_idx',$searchinputdata);

returns Blind Index (ssn_last_four_idx) as 1258bc5e

But when i tried to get compound index only with email, then it returns new compound index

$row->getBlindIndex('ssnlast4_hivstatus_cidx',$searchinputdata_cidx);

returns Compound Index (ssnlast4_hivstatus_cidx) as 1a1937b2

I need the clarification and help on this issue to achieve the search with compound index and decrypt the same.

Thanks

@paragonie-security
Copy link
Contributor

Why are you adding two indexes for one? Choose either blind index or compound index, not both.

They're not interoperable; a single Compound Index is intended to be computed over multiple fields at once. This adds some overhead.

Additionally, the index key will always be distinct for two different indexes, even if you mostly define them the same. (Their names must differ, but that's also a requirement to get more than 1 index out of CipherSweet anyway.)

@MadhavPrabu
Copy link
Author

MadhavPrabu commented Oct 8, 2021

Hi,
Okay, i will use only compound index and not use blind index. But i need to search a particular field value in a compound index.
For example, consider that i had created a compound index as address_cidx with the fields address,city,state.country,zip
Step:1
And the plaintext value for each fields is like address:myaddress_line, city:mycity, state:mystate. country:mycountry, zip:myzip
And compound index value created for the above data as 9fbf99d5.

Step:2
Store the encrypted data with compound index value in database.

Step:3
Now i need to search data with city:mycity using compound index without passing the other fields data. How can i get it.
If i try to do, it will give new different compound index (1a1937b2) which are not matched with existing index which we stored in Step-2.

But if i passed all the values like address:myaddress_line, city:mycity, state:mystate,. country:mycountry, zip:myzip then it gives the same index as 9fbf99d5

I need to search any of the combination or individual field value in compound index to search that if available or not.

For example, search with different combination of fields like,
address
city
state
zip
country
address,city
city,state
city,state,country
city,state,country,zip
address, city,state
address, city,state,country
address, city,state,country,zip
city, zip,
city,state,zip
address,city,zip
address,city,state,zip
zip,country

Can we do the search like this with compound index?

I need the clarification or solution to the above mentioned points that how to do this. If possible please share some examples in PHP

Thanks

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