SQL Server 2005 MD5 functions

Source: Internet
Author: User
Tags md5 encryption sha1 sha1 encryption
Original: SQL Server 2005 MD5 function

In SQL Server 2005, the function Hashbytes (), which is provided by Microsoft in SQL Server 2005, can be used to calculate the MD5 and SHA1 values of a string, using the following method:--Get 123456 MD5 encryption string Select Hashbytes (' MD5 ', ' 123456 ');--Get 123456 of the SHA1 encryption string Select Hashbytes (' SHA1 ', ' 123456 '); With this function you can encrypt a string in SQL Server, However, the return result of the hashbytes () function is the varbinary type (binary data in 16 binary form, starting with 0x). Normally, all we need is string data, and the first thing many people think of is to convert varbinary to varchar with the cast or CONVERT function, but then the converted result is garbled, Correct conversion of varbinary variable-length binary data to 16 binary strings should use the system built-in function sys.fn_varbintohexstr () or SYS.FN_SQLVARBASETOSTR (only available under SQL Server2005), As follows: Select Sys.fn_varbintohexstr (hashbytes (' MD5 ', ' 123456 ')) then you can intercept the desired part: Set Right (SYS.FN_VARBINTOHEXSTR ( Hashbytes (' MD5 ', ' 123456 ')), 32) Encrypt the string for MD5.

SQL Server 2005 MD5 functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.