2011-04-08 26 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== 
    } 
}