2

Say I have table:

Fee date : DATE amount : INT

I can't store data in amount column in virgin way, because this is private information, so I need to encrypt it. Also I need to perform arithmetic operations on that encrypted column, like: SELECT SUM(amount) FROM Fee;

What is the best way to do that? Thank you.

5
  • 2
    Take a look at en.m.wikipedia.org/wiki/Homomorphic_encryption Commented May 2, 2014 at 9:50
  • 1
    crypto.cs.virginia.edu/courses/14s-pet/… Commented May 2, 2014 at 9:54
  • Konstantin, thank you. So I think I need to perform homomorpic encryption on client, but I can't find any implementation of homomorpic encryption algorythm for SUM operation. Commented May 2, 2014 at 10:27
  • 1
    You could try to ask at crypto.stackexchange.com Commented May 2, 2014 at 10:54
  • This is the subject of lots of cryptography research, but in general is very difficult. The more common solution is to do the equivalent of select sum( decrypt_int(amount, 'thekeydata') ) from ..., i.e. you must know the key to perform operations like a sum. Commented May 3, 2014 at 4:54

1 Answer 1

1

Why not use Postgres's built-in column-level security?

Code:

create table employees (
    id int primary key,
    name text not null,
    salary decimal(10,2) not null 
);

insert into employees values (1, 'Frank', 60000.00);

create or replace view employees_view as 
    select
        id,
        name,
        case when has_column_privilege('employees', 'salary', 'select') then salary else null end as salary
    from employees;

create role managers;
create role clerks;

grant select on employees_view to managers;
grant select on employees_view to clerks;

grant select (salary) on employees to managers;

set role managers;
select * from employees_view;

Result: 1, 'Frank', 60000.00

set role clerks;
select * from employees_view;

Result: 1, 'Frank', null

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.