當前位置:首頁 » 密碼管理 » 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
熱點內容
c語言中怎麼賦值 發布:2025-09-19 01:17:43 瀏覽:956
公網伺服器如何共享ip 發布:2025-09-19 01:03:43 瀏覽:237
存儲器已幾乎滿 發布:2025-09-19 00:36:28 瀏覽:884
安卓系統在哪裡輸入網址 發布:2025-09-19 00:35:46 瀏覽:173
armlinuxgccgcc 發布:2025-09-19 00:35:37 瀏覽:425
wincachephp 發布:2025-09-19 00:30:28 瀏覽:863
如何給文件夾設置圖標 發布:2025-09-19 00:06:09 瀏覽:752
火車頭密碼指紋鎖多少錢 發布:2025-09-18 23:16:55 瀏覽:139
雪佛蘭最高配置長什麼樣 發布:2025-09-18 23:16:54 瀏覽:173
網路通話源碼 發布:2025-09-18 23:07:23 瀏覽:92