25 fsWrite.Write(md5, 0, md5.Length); 26 //fsWrite.Write(pdfFile, 10, pdfFile.Length - 10); 27 fsWrite.Close(); 28 29 return result; 30 } 31 catch (Exception e) 32 { 33 return e.ToString(); 34 } 35 } 36 /**//// <summary> 37 /// 对给定路径的文件进行验证 38 /// </summary> 39 /// <param name="path"></param> 40 /// <returns>是否加了标签或是否标签值与内容值一致</returns> 41 public static bool Check(string path,string key) 42 { 43 try 44 { 45 FileStream get_file = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read); 46 47 48 byte[] pdfFile = new byte[get_file.Length]; 49 get_file.Read(pdfFile, 0, (int)get_file.Length); 50 get_file.Close(); 51 string result = MD5Buffer(pdfFile, 0, pdfFile.Length - 32);//对pdf文件除最后32位以外的字节计算MD5,这个32是因为标签位为32位。 52 result = MD5String(result + key); 53 54 string md5 = System.Text.Encoding.ASCII.GetString(pdfFile, pdfFile.Length - 32, 32);//读取pdf文件最后32位,其中保存的就是MD5值 55 return result == md5; 56 } |