Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello everyone!
I have a table in sqlserver, my table has a field as string, for example FirstName (it's just example!). This field "EncryptByPassPhrase" before insert on database.

Before encode: Ali
After  encode: 0x010000001D905174BB7947AE1C600A4AB564A123310F92C21C9A4221

Now i would search on this field for example i would get all fields that contains charcters 'Al'.
I can decode this field and search on such as:
SQL
select * from EncodeTest e
where  dbo.Decoder(e.FirstName) like '%Al%'


But this way very slow on many numbers of record.
Please help me for best solution.

Thanks.

What I have tried:

SQL
declare @EncodedName varbinary(max)
select @EncodedName =EncryptByPassPhrase('key', cast( @Name as varbinary(max)) )


declare @DecodedName nvarchar(max)
select @DecodedName=convert(varchar(100),DecryptByPassPhrase('key',cast( @EncodedName as varbinary(max)) ))

select * from EncodeTest e
where dbo.Decoder(e.FirstName) like '%Al%'
Posted
Updated 12-Nov-18 20:36pm

1 solution

Plan ahead.

Decrypt once; query multiple times.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900