新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
在网上搜索VB MD5 会搜索到一大堆MD5的类,
成都创新互联-专业网站定制、快速模板网站建设、高性价比抚顺网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式抚顺网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖抚顺地区。费用合理售后完善,10多年实体公司更值得信赖。
复制到项目中粘贴,
调用的时候使用函数名md5(值) 就可以了!
下面是完整的类,可以设置任意密码
'DES及md5加密解密----添加引用中添加对system.web的引用。
Imports System.Security.Cryptography
Imports System
Imports System.Text
Imports System.Web
''' summary
''' DES加密类
''' /summary
''' remarks/remarks
Public Class DESEncrypt
Public Sub DESEncrypt()
End Sub
Public Shared Function Encrypt(ByVal Text As String) As String
Return Encrypt(Text, "12345678")
End Function
Public Shared Function Encrypt(ByVal Text As String, ByVal sKey As String) As String
Dim des As New DESCryptoServiceProvider()
Dim inputByteArray As Byte()
inputByteArray = Encoding.Default.GetBytes(Text)
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))
Dim ms As New System.IO.MemoryStream()
Dim cs As New CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)
cs.Write(inputByteArray, 0, inputByteArray.Length)
cs.FlushFinalBlock()
Dim ret As New StringBuilder()
Dim b As Byte
For Each b In ms.ToArray()
ret.AppendFormat("{0:X2}", b)
Next
Return ret.ToString()
End Function
Public Shared Function Decrypt(ByVal Text As String) As String
Return Decrypt(Text, "12345678")
End Function
Public Shared Function Decrypt(ByVal Text As String, ByVal sKey As String) As String
Dim des As New DESCryptoServiceProvider()
Dim len As Integer
len = Text.Length / 2
Dim inputByteArray(len - 1) As Byte
Dim x, i As Integer
For x = 0 To len - 1
i = Convert.ToInt32(Text.Substring(x * 2, 2), 16)
inputByteArray(x) = CType(i, Byte)
Next
des.Key = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))
des.IV = ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))
Dim ms As New System.IO.MemoryStream()
Dim cs As New CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write)
cs.Write(inputByteArray, 0, inputByteArray.Length)
cs.FlushFinalBlock()
Return Encoding.Default.GetString(ms.ToArray())
End Function
End Class
'以下是调用方法
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '加密
Dim str_Encrypt As String = DESEncrypt.Encrypt("你要加密的文本,可以是任意长度", "密码,可以很长,如果省略这个参数就是默认的12345678")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click '解密
Dim str_Decrypt As String = DESEncrypt.Decrypt("你要解密的文本, 可以是任意长度", "加密时用到的密码,如果省略这个参数就是默认的12345678")
End Sub
using System;
using System.Text;
using System.Security.Cryptography;
namespace MD5
{
public class MD5
{
// 32 位
public static String Encrypt(String s)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
bytes = md5.ComputeHash(bytes);
md5.Clear();
string ret = "";
for (int i = 0; i bytes.Length; i++)
{
ret += Convert.ToString(bytes[i], 16).PadLeft(2, '0');
}
return ret.PadLeft(32, '0');
}
// 16 位
public static string Encrypt16(string ConvertString)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
t2 = t2.Replace("-", "");
return t2;
}
}
}
-------------------------------------
引用MD5命名空间
using MD5;
直接用MD5.Encrypt(textbox1.Text);即可加密;
MD5没有解密的算法,要不然就不用加密了,网上有一些解密的网站,有些能解密,有些解密不了,有些还需要收费才能解密。