1

Here is my code to encrypt the column:

UPDATE users 
SET  (userid, modifieddate) = 
(
    PGP_SYM_ENCRYPT('0', 'AES_KEY'),
    PGP_SYM_ENCRYPT('2018-06-19 08:40:23', 'AES_KEY')
) 
WHERE id='3';

but its throwing error:

column "userid" is of type integer but expression is of type byte

2 Answers 2

1

Your table columns users.userid and users.modifieddate should be type BYTEA, because pgcrypto module generates encrypted result with BYTEA type.

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

2 Comments

i cannot alter my table data types
@adams I am facing a similar issue, did you find a solution such that you can encrypt numeric data and persist the datatype as well?
0

You cannot encrypt only one user's id and put rest of it as it is , if you want to achieve that you need to alter table as mention by @C.C. Hsu , i.e. to converting data type of userid , modifieddate into bytea or text which is capable of storing both encrypted data and your normal data.

alter table users alter column userid type bytea using PGP_SYM_ENCRYPT(userid::text, 'AES_KEY');
alter table users alter column modifieddate type bytea using PGP_SYM_ENCRYPT(modifieddate::text, 'AES_KEY');

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.