Original: SQL Server built-in function implements MD5 encryption
Instance
MD5 Encryption "123456":
hashbytes ('MD5','123456')
Result: 0xe10adc3949ba59abbe56e057f20f883e (hint: After the end, the result is converted. )
function
Function |
Describe |
return value |
Hashbytes |
Hashbytes (' encryption method ', ' value to encrypt ') Encryption mode = MD2 | MD4 | MD5 | SHA | SHA1 |
Return value type:varbinary(maximum 8000 bytes) |
Hints and notes
123456 of MD5 have tools to know the result: e10adc3949ba59abbe56e057f20f883e
The result of the hashbytes is: The value of 0xe10adc3949ba59abbe56e057f20f883e,16, minus "0x" converted to lowercase value is exactly the same as the MD5 value, where another function (sys) is required. fn_sqlvarbasetostr) Convert the value of varbinary to a varchar type, complete SQL is as follows:
Select substring (sys. FN_SQLVARBASETOSTR (hashbytes('MD5','123456 ')),3,+)
The result is the complete MD5 value: e10adc3949ba59abbe56e057f20f883e
At last
Since the choice of distance, it is only the trials and tribulations, since the goal is the horizon, leaving the world can only be back.
Hope to work with our compatriots, to find fun in the job, in order to live, for ourselves, refueling!
SQL Server built-in functions implement MD5 encryption