Before we look into how to implement hashing in SQL Server, we need to understand the difference between hashing and encryption.
Encryption VS Hashing:
Encryption its a reversible operation i.e., you can decrypt the encrypted value with a key.Hashing value cannot decrypted back to its original value.
HASHBYTES:
HASHBYTES function in SQL Server returns the hash value of a given input string.
this function uses following algorithms to hash the value.
- MD2
- MD4
- MD5
- SHA
- SHA1
- SHA2
- SHA2_256(Applies to SQL Server 2012 to SQL Server 2014)
- SHA2_512(Applies to SQL Server 2012 to SQL Server 2014)
this function returns type is Varbinary
syntax:
HASHBYTES ( '<algorithm>', { @input | 'input' } )
Example:
DECLARE @HashThis nvarchar(4000);
SET @HashThis = CONVERT(nvarchar(4000),'pranay1231232');
SELECT HASHBYTES('SHA1', @HashThis);
Result:
0x52A99EAE34513AB695801F775D9F9FE2EEBBF3DB
we can use this function while storing the User Sensitive data.This is the much simple approach than TDE.
No comments:
Post a Comment