2011-04-08 30 views

回答

4

什么样的嵌入式资源是它的文件)?如果这是一个你使用Assembly.GetManifestResourceStream()的保持,那么最简单的方法是:

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

如果没有帮助,请提供更多的信息,告诉你如何normall访问/提取您的资源。

+0

仅一个侧面说明...如果你想重用sream使用stream.position = 0 ...感谢您的代码 – VSP 2011-04-08 12:01:16

0

可以使用的MemoryStream

using (MemoryStream ms = new MemoryStream(Properties.Resources.MyZipFile)) 
{ 
    using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create()) 
    { 
    byte[] hash = md5.ComputeHash(ms); 
    string str = Convert.ToBase64String(hash); 
    // result for example: WgWKWcyl2YwlF/C8yLU9XQ== 
    } 
}