vb.net文件md5 windows 文件md5

VB.NET 獲取文件MD5值

Public Function md5(ByVal a As String) As String

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比衡南網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式衡南網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋衡南地區(qū)。費(fèi)用合理售后完善,十余年實體公司更值得信賴。

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 控件 在運(yùn)行時,由于有 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

加密解密高手進(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

希望能幫到你

網(wǎng)站標(biāo)題:vb.net文件md5 windows 文件md5
本文網(wǎng)址:http://muchs.cn/article28/docdccp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃搜索引擎優(yōu)化、ChatGPT、外貿(mào)網(wǎng)站建設(shè)、做網(wǎng)站、網(wǎng)站設(shè)計公司

廣告

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

h5響應(yīng)式網(wǎng)站建設(shè)