當前位置:首頁 » 密碼管理 » md5加密函數

md5加密函數

發布時間: 2024-09-22 21:02:32

⑴ 求VB.NET的MD5演算法調用

下面是完整的類,可以設置任意密碼

'DES及md5加密解密----添加引用中添加對system.web的引用。
ImportsSystem.Security.Cryptography
ImportsSystem
ImportsSystem.Text
ImportsSystem.Web
'''<summary>
'''DES加密類
'''</summary>
'''<remarks></remarks>
PublicClassDESEncrypt
PublicSubDESEncrypt()
EndSub
PublicSharedFunctionEncrypt(ByValTextAsString)AsString
ReturnEncrypt(Text,"12345678")
EndFunction
PublicSharedFunctionEncrypt(ByValTextAsString,ByValsKeyAsString)AsString
()
DiminputByteArrayAsByte()
inputByteArray=Encoding.Default.GetBytes(Text)
des.Key=ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.(sKey,"md5").Substring(0,8))
des.IV=ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.(sKey,"md5").Substring(0,8))
DimmsAsNewSystem.IO.MemoryStream()
DimcsAsNewCryptoStream(ms,des.CreateEncryptor(),CryptoStreamMode.Write)
cs.Write(inputByteArray,0,inputByteArray.Length)
cs.FlushFinalBlock()
DimretAsNewStringBuilder()
DimbAsByte
ForEachbInms.ToArray()
ret.AppendFormat("{0:X2}",b)
Next
Returnret.ToString()
EndFunction
PublicSharedFunctionDecrypt(ByValTextAsString)AsString
ReturnDecrypt(Text,"12345678")
EndFunction
PublicSharedFunctionDecrypt(ByValTextAsString,ByValsKeyAsString)AsString
()
DimlenAsInteger
len=Text.Length/2
DiminputByteArray(len-1)AsByte
Dimx,iAsInteger
Forx=0Tolen-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.(sKey,"md5").Substring(0,8))
des.IV=ASCIIEncoding.ASCII.GetBytes(System.Web.Security.FormsAuthentication.(sKey,"md5").Substring(0,8))
DimmsAsNewSystem.IO.MemoryStream()
DimcsAsNewCryptoStream(ms,des.CreateDecryptor(),CryptoStreamMode.Write)
cs.Write(inputByteArray,0,inputByteArray.Length)
cs.FlushFinalBlock()
ReturnEncoding.Default.GetString(ms.ToArray())
EndFunction
EndClass
'以下是調用方法
PublicClassForm1
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.Click'加密
Dimstr_EncryptAsString=DESEncrypt.Encrypt("你要加密的文本,可以是任意長度","密碼,可以很長,如果省略這個參數就是默認的12345678")
EndSub
PrivateSubButton2_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton2.Click'解密
Dimstr_DecryptAsString=DESEncrypt.Decrypt("你要解密的文本,可以是任意長度","加密時用到的密碼,如果省略這個參數就是默認的12345678")
EndSub
熱點內容
電腦上哪個游戲可以移植到安卓上 發布:2025-03-14 00:10:32 瀏覽:471
tcl編譯器 發布:2025-03-13 23:52:59 瀏覽:322
linuxnamed 發布:2025-03-13 23:45:29 瀏覽:361
阿里雲30元伺服器 發布:2025-03-13 23:21:25 瀏覽:351
pythonstatvfs 發布:2025-03-13 23:14:55 瀏覽:954
火車上有密碼多少 發布:2025-03-13 23:14:10 瀏覽:865
解壓火柴 發布:2025-03-13 22:46:39 瀏覽:336
開機密碼在哪裡存著 發布:2025-03-13 22:27:22 瀏覽:952
光流場演算法 發布:2025-03-13 21:35:51 瀏覽:896
免編程軸控 發布:2025-03-13 21:19:24 瀏覽:782