Transferred from: http://www.maomao365.com/?p=4732
I. Introduction to MSSQL SQL Hashbytes function
The Hashbytes function functions as: Returns a character,
Return values after encryption via MD2, MD4, MD5, SHA, SHA1, sha2_256, sha2_512
Hashbytes (' parameter 1 ', ' parameter 2 ')
Parameter 1:
Input Encryption Type example: MD5
Parameter 2:
Enter the string to be encrypted (the maximum value of the encrypted string is 8000 bytes)
return value:
The maximum return value is 8000 bytes
Precautions:
When an exception is entered for the encryption type, NULL is returned
Second, MSSQL SQL Hashbytes example Application
Example 1:
DECLARE @info nvarchar(4000); SET @info = CONVERT(nvarchar(4000),'www.maomao365.com'); SELECTHashbytes ('SHA1',@info);---Return with SHA1 encryptionSELECTHashbytes ('MD5',@info);---Return with MD5 encryptionSELECTHashbytes ('MD2',@info);---Return with MD2 encryption
Example 2:
Create TableA (info1varchar( -))Insert intoA (INFO1)Values('www.maomao365.com')Insert intoA (INFO1)Values('cat and Cat Hut')Insert intoA (INFO1)Values('MSSQL Tutorial Dedicated')Insert intoA (INFO1)Values('Introduction to MSSQL function usage') SelectHashbytes ('Md5', INFO1) as [MD5 Encryption], Hashbytes ('SHA1', INFO1) as [SHA1 Encryption], Info1 fromAtruncate TableADrop TableA
MSSQL SQL Cryptographic function Hashbytes Usage Introduction