魅影醉

Thứ Sáu, 2 tháng 9, 2016

E807F1FCF82D132F9BB018CA6738A19F

C#:
textBox2.Text = md5(textBox1.Text);
Code:
public static byte[] encryptData(string data)
    {
        System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
        byte[] hashedBytes;
        System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
        hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
        return hashedBytes;
    }
public static string md5(string data)
        {
            return BitConverter.ToString(encryptData(data)).Replace("-","").ToLower();
        }

VB:
TextBox2.Text = md5(TextBox1.Text)
Code:
Public Shared Function encryptData(data As String) As Byte()
    Dim md5Hasher As New System.Security.Cryptography.MD5CryptoServiceProvider()
    Dim hashedBytes As Byte()
    Dim encoder As New System.Text.UTF8Encoding()
    hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data))
    Return hashedBytes
End Function
Public Shared Function md5(data As String) As String
    Return  BitConverter.ToString(encryptData(data)).Replace("-","").ToLower()
End Function

ToLower()
ToUpper()

md5("1234567890")
ToLower() : e807f1fcf82d132f9bb018ca6738a19f
ToUpper() : E807F1FCF82D132F9BB018CA6738A19F

Không có nhận xét nào:

Đăng nhận xét