C#在提取嵌入式资源之前获取md5哈希 [英] c# get md5 hash of an embedded resource before extracting it

查看:61
本文介绍了C#在提取嵌入式资源之前获取md5哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个嵌入式资源,在提取文件之前需要获取文件的md5哈希值,以便知道它是否与现有文件不同(因为如果我们必须提取它来进行比较,会更好)直接替换文件)

We have an embedded resource and need to get the md5 hash of the file before extracting it in order to know if it is different from an already existing file, (becouse if we have to extract it to compare them it would be better to replace the file directly)

任何建议都值得赞赏

推荐答案

它是哪种嵌入式资源?如果您可以使用 Assembly.GetManifestResourceStream(),那么最简单的方法是:

What sort of embedded resource is it? If it's one you get hold of using Assembly.GetManifestResourceStream(), then the simplest approach is:

using (Stream stream = Assembly.GetManifestResourceStream(...))
{
    using (MD5 md5 = MD5.Create())
    {
        byte[] hash = md5.ComputeHash(stream);
    }
}

如果这没有帮助,请提供更多有关您正常访问/提取资源的信息.

If that doesn't help, please give more information as to how you normall access/extract your resource.

这篇关于C#在提取嵌入式资源之前获取md5哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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