用目录作为字符串计算MD5哈希值? [英] Calculate MD5 Hash with directory as string?

查看:84
本文介绍了用目录作为字符串计算MD5哈希值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有点问题。我正在尝试为给定文件执行MD5哈希算法,但我所拥有的只是作为字符串的目录。



例如我将此作为我的字符串..

C:\ Users \Subfolder\file.exe



如何使用字符串找到文件然后再计算文件的md5哈希值而不仅仅是字符串的md5计算?



提前谢谢!

Hello I have somewhat of a problem. I am trying to execute a MD5 hashing algorithm for a given file but all I have is the directory as a string.

for example I have this as my string..
C:\Users\Subfolder\file.exe

How can I use the string to locate the file to then calculate the md5 hash of the file and not just the md5 calculation of the string?

thank you in advance!

推荐答案

Imports System.Security.Cryptography
Imports System.Text
Imports System.IO

Public Function MD5FileHash(ByVal sFile As String) As String
    Dim MD5 As New MD5CryptoServiceProvider
    Dim Hash As Byte()
    Dim Result As String = ""
    Dim Tmp As String = ""

    Dim FN As New FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
    MD5.ComputeHash(FN)
    FN.Close()

    Hash = MD5.Hash
    Result = Strings.Replace(BitConverter.ToString(Hash), "-", ""
    Return Result
End Function





应该这样做^^



should do the trick ^^


这篇关于用目录作为字符串计算MD5哈希值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆