vb.net加入md5 net md5

vb.net 怎么計算選擇的文件md5值,寫在textbox中?

Public Function md5(ByVal a As String) As String

清水河ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!

Dim tempmd5 As System.Security.Cryptography.MD5 = New System.Security.Cryptography.MD5CryptoServiceProvider()

Dim bytResult() As Byte = tempmd5.ComputeHash(System.Text.Encoding.Default.GetBytes(a))

Dim strResult As String = BitConverter.ToString(bytResult)

strResult = strResult.Replace("-", "")

Return strResult

End Function

如果要計算文件的就把參數(shù)改成字節(jié)數(shù)組就可以了,然后獲取文件GetBytes()傳進(jìn)去就可以了。

vb.net 怎么獲取一個文件夾所有文件的MD5值

VB可使用DriveListBox 控件,DirListBox 控件和FileListBox 控件組合使用獲取文件夾里的文件數(shù)量(包括文件夾)。 DriveListBox 控件 在運行時,由于有 DriveListBox 控件,所以可選擇一個有效的磁盤驅(qū)動器。

求VB.NET的MD5算法調(diào)用

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

'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

'以下是調(diào)用方法

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("你要加密的文本,可以是任意長度",?"密碼,可以很長,如果省略這個參數(shù)就是默認(rèn)的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("你要解密的文本,?可以是任意長度",?"加密時用到的密碼,如果省略這個參數(shù)就是默認(rèn)的12345678")

End?Sub

怎么在.net上實現(xiàn)MD5crypt的加密(最好vb.net代碼)

MD5實際一種單向的算法,是散列,很多人認(rèn)為是加密,實際有誤

比如說winxp、win7各版本都有MD5值,那么是否可依據(jù)這個值還原出個正版的winxp或win7呢?

況且MD5“加密”的密鑰長度又是多少呢?比如des的不同版本有64位、128位、192位等

加密解密高手進(jìn)!VB.NET 誰能給一個MD5或其他的加密算法

這個是我之前寫的。在需要時調(diào)用即可。

Public Shared Function Encrypt(ByVal Text As String, ByVal sKey As String) As String

Dim provider As New DESCryptoServiceProvider()

Dim bytes As Byte() = Encoding.[Default].GetBytes(Text)

provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))

provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8))

Dim stream As New MemoryStream()

Dim stream2 As New CryptoStream(stream, provider.CreateEncryptor(), CryptoStreamMode.Write)

stream2.Write(bytes, 0, bytes.Length)

stream2.FlushFinalBlock()

Dim builder As New StringBuilder()

For Each num As Byte In stream.ToArray()

builder.AppendFormat("{0:X2}", num)

Next

Return builder.ToString()

End Function

希望能幫到你

文章題目:vb.net加入md5 net md5
本文路徑:http://muchs.cn/article38/dooogpp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、定制開發(fā)、關(guān)鍵詞優(yōu)化網(wǎng)站設(shè)計公司、靜態(tài)網(wǎng)站網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運營