Home » Java » MD5 encryption algorithm (salt salt encryption)

MD5 encryption algorithm (salt salt encryption)

MD5 encryption algorithm (salt salt encryption), there is a need for friends, you can refer to.

MD5 encryption algorithm:

MD5 encryption algorithm is not reversible that is not able to decode the source string to get to the need to verify if the password is correct to treat the same password verification and MD5 encryption are compared and stored in the database encrypted data;

Regular MD5 encryption is not secure, and we can encrypt salt strings by repeatedly encrypting MD5 or using Salt

How to use: we can randomly generate salt salt, and then we want to encrypt the string to be spliced, and then encrypted with MD5, and then on the stitching, we just salt

When verifying, we first intercept the first two bytes of the encrypted string in the database to obtain our salt, and use this salt as the encryption method to verify the secret

we need to verify

Public, static, string, MD5 (string, PWD)


String = "MD5pwd"; / / define a string to string encoding after receiving

MD5CryptoServiceProvider MD5 = new (MD5CryptoServiceProvider); / / define a MD5 object

Or MD5, md5=MD5.Create ();

Byte[] buffer = Encoding.UTF8.GetBytes (PWD); / / all encryption algorithm is byte encryption, because the password is converted into an array of bytes

Or byte[], buffer=, System.Text.Encoding.Default.GetBytes (PWD);

byte[] MD5buffer = MD5.ComputeHash (buffer);
On / / byte encryption, returns a byte array

Foreach (byte, item, in, MD5buffer),

//md5 encryption is obtained: 32 is the 16 hexadecimal number, all the btye into sixteen decimal


MD5pwd = item.ToString ("X2");
//x said sixteen hexadecimal number is converted into capital [x said sixteen hexadecimal letters in uppercase]


Return MD5pwd;