0

I have some data in CSV file, say data.csv with columns age, sex, country and status. Is it possible I could encrypt the entire CSV file some way which allows me to fetch only selected columns, say country and status, from the encrypted file and then decrypt to get back only those fields in clear text?

I am talking something similar to column-based encryption available in some databases but I cannot use any databases.

One idea I have is while encryption i encrypt each field column one by one, put a delimeter and then encrypt other field and append to the previously encrypted field but i am certain its a bad approach.

  • When you encrypt the whole file, decryption of specific fields will be problematic. It looks like for your use case need to protect parts of your file where secret info is located. – VovCA Apr 4 '18 at 18:14
  • What kind of encryption ? A hash function, what exactly ? – game0ver Apr 4 '18 at 21:10
  • Hash function is one way function, it's not encryption. Encryption would be probably something like AES 128 CBC or AES 128 CTR modes. – VovCA Apr 4 '18 at 21:32
  • Can you clarify your requirements a bit? Why not just decrypt the whole file, but only use the column you are interested in? – Anders Apr 5 '18 at 14:40
  • I am working on Intel SGX where the enclave has limited memory, I do wanted to bring the entire csv inside enclave and do the decryption as the entire csv file is too large. I am using aes gcm 256. – Roshan Mehta Apr 5 '18 at 14:42
1

Transpose the CSV before encrypting. So each column is its own contiguous block.

So the CSV:

a,b,c
1,2,3
4,5,6
7,8,9

is stored as three blocks. The format of these only requires that you have some way of finding the beginning of each column in the file and that you have some way of delimiting values. I am not specifying an encoding. But one could use CSV encoding for the values where the spaces in the following are actually commas and the values are a single line.

a 1 4 7
b 2 5 8
c 3 6 9

Each of the lines represents a block where the part in brackets is encrypted:

a [1 4 7]
b [2 5 8]
c [3 6 9]

Then you can iterate over the rows by doing decryption steps on each column and merging their output to produce rows as the values may be of variable length the amount of decryption steps on a column depends on the length of the value in that column.

  • So you mean to say I encrypt line by line after transpose? – Roshan Mehta Apr 6 '18 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.