I have a requirement to encrypt several columns using encrypt by passphrase method. unfortunately these encrypted columns need to be used in joins to one another. and there are many views stored procs etc that I don't want to have to modify.
here is a fiddle of what is beneath if you would like to try it https://dbfiddle.uk/?rdbms=sqlserver_2017&fiddle=cc71b4969526eb0fedd22de2828abaa3
setup
create table encrypt.empsone(empno varchar(10),empno_encrypted varbinary(100));
create table encrypt.empstwo(empno varchar(10),empno_encrypted varbinary(100));
insert into encrypt.empsone(empno, empno_encrypted )
values('001', EncryptByPassPhrase('my passphrase','001'))
insert into encrypt.empstwo(empno, empno_encrypted )
values('001', EncryptByPassPhrase('my passphrase','001'))
everything looks ok
select a.empno,
CONVERT(varchar,(DECRYPTBYPASSPHRASE('my passphrase', a.empno_encrypted))) from encrypt.empsone a
empno no name
001 001
but the join does not work
select * from encrypt.empsone a join encrypt.empstwo b
on a.empno_encrypted = b.empno_encrypted
I am assuming because the encrypted values are not identical is there an option in encrypt by passcode to achieve this? I am hopeful I do not need to rewrite all of the joins to use the decryptbypassphrase function