파일 경로를 입력하면 해당 파일의 MD5 Hash를 스트링으로 반환해준다.
스코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | Imports System.Security.Cryptography
Public Function GetMD5Hash(ByVal sFilePath As String) As String
Dim RD As FileStream = New FileStream(sFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
RD = New FileStream(sFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
md5.ComputeHash(RD)
RD.Close()
Dim hash As Byte() = md5.Hash
Dim SB As StringBuilder = New StringBuilder
Dim HB As Byte
For Each HB In hash
SB.Append(String.Format("{0:X1}", HB))
Next
Return SB.ToString
End Function |
사용예제
1 2 | Dim sHash as String
sHash = GetMD5Hash("C:\Test.txt") |
'프로그래밍 > VB.net' 카테고리의 다른 글
VB.net - 컨트롤 이름으로 컨트롤 접근 (0) | 2015.05.11 |
---|---|
VB.net - 문자열로 Form 객체 반환 받기 (0) | 2015.05.11 |