Thursday, 22 November 2018

SQL Server Query Plan

-- SQL Server Query Plan

select

cp.usecounts,
cp.cacheobjtype,
cp.objtype,
st.[text],
qp.query_plan

from

sys.dm_exec_cached_plans as cp

cross apply

sys.dm_exec_sql_text(plan_handle) as st

cross apply

sys.dm_exec_query_plan(plan_handle) as qp

order by

cp.usecounts desc;
go

dbcc

freeproccache;

Monday, 29 October 2018

Obfuscation using SQL Server ENCRYPTBYPASSPHRASE and DECRYPTBYPASSPHRASE functions

--Obfuscation using SQL Server ENCRYPTBYPASSPHRASE and DECRYPTBYPASSPHRASE functions

-- 01 Obfucate (encrypt) Value

-- Theory Obfucate Value
-- select EnCRYPTBYPASSPHRASE('Phrase to use to decode','Value to encrypt')

-- Example Obfucate Value
select ENCRYPTBYPASSPHRASE('Test1','Test');


-- 02 Unobfucate (unencrypt) Value

-- Theory decrypt Value
-- select convert(varchar(max),DECRYPTBYPASSPHRASE('Phrase to use to decode',EnCRYPTBYPASSPHRASE('Phrase to use to decode','Value to encrypt')));

-- Example decrypt value
select convert(varchar(max),DECRYPTBYPASSPHRASE('Test1',EnCRYPTBYPASSPHRASE('Test1','Test')));