SQL dumps raw data for MD5 encryption

Source: Internet
Author: User
Tags md5 encryption

First to describe the situation, first there is a batch of users before the default password for 6 8 and then after the MD5 encryption for storage, it is now necessary to change according to the user ID number 6 digits as the password.

1. First found that we sqlserver05 the above version is the MD5 encryption method, and then we verify that its encrypted data with the. NET comes with the MD5 encryption method is the same after encryption.

SQL Server Fetch MD5 method: Select Hashbytes (' MD5 ', ' 888888 ')

The result is that the 16 binary is not the same as what we need.

Make a built-in conversion and intercept the data that forms the MD5 encryption we need to result in

Then we test the encrypted data in. NET to see if the encryption is compliant

Find the same value as the encryption we have in SQL, which means that the encryption method is consistent.

2. Down we go to the database to operate!

After performing the update operation to the system after the check found that the wrong up.

Go back to the database and check. (The search is consistent, this way because the user name is the ID card number (userid), so the userid of the table after the interception of 6 bits and then encrypted processing)

Select Top substring (sys.fn_sqlvarbasetostr (hashbytes (' MD5 ', substring (UserID) -5,6)), Userid,len), SUBSTRING (Userid,len (UserID) -5,6), UserID from db_owner. SystemUser where db_owner. Systemuser.roleguid=25

The result is that the data that was intercepted from the database and then encrypted is different from the value that we manually entered.

We later found that we used the nvarchar type when we stored the UserID, which is actually twice times the number of bytes. The value after encryption is different for this reason.

After it has been converted to varchar for testing


Select Top substring (sys.fn_sqlvarbasetostr (hashbytes (' MD5 '), CAST (substring (Userid,len (UserID) -5,6) as varchar ( )), 3,32), substring (Userid,len (UserID) -5,6), UserID from db_owner. SystemUser where db_owner. Systemuser.roleguid=25

The findings are the same as the results we expected.

SQL dumps raw data for MD5 encryption

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.