【问题标题】:File format issue (plaintext)文件格式问题(明文)
【发布时间】:2012-06-21 23:07:02
【问题描述】:

我收到一封带有附件的电子邮件,该附件是一个 zip 文件。由于某种原因,电子邮件客户端没有将其作为单独的文件附加,而只是将其呈现为电子邮件中的文本。该 zip 文件没有其他副本。我正在尝试恢复它,但不知道是否可能。电子邮件以文本形式显示这样的文件;

>Content-Type: application/x-zip-compressed; name="me.zip";
>
>Content-Disposition: attachment; filename="me.zip"
>
>Content-Transfer-Encoding: base64
>
>
>
>UEsDBBQAAQAIANeV9y5y6d5oG..... etc.

它只是以随机字母持续很长时间。有谁知道是否有可能恢复这样的文件?

感谢您的任何指点。

【问题讨论】:

  • 我只是要求这个人再次发送 zip ......正确。
  • 创建一个空的 .txt 文件,将 UEsD... 文本粘贴到其中。将文件重命名为 .zip 并查看它是否有效?我不知道,但我会试一试..

标签: c# encryption winzip


【解决方案1】:

它是一个base64编码的文件,你可以简单地解码base64编码的字符并将结果输出到一个文件中(由于它是加密的,它将是二进制数据,所以看起来更奇怪)。

线索在Content-Transfer-Encoding 标头中。

【讨论】:

  • 那么 zip 文件是加密的 - 所以你是说我可以解码然后输出到一个文件并重命名为 .zip?
  • @creative 理论上,是的,你会这样做。
  • 我将文本复制到网站base64decode.org。然后我复制了翻译并将其保存为文本文件,然后将其重命名为 .zip。您可以看到 base64 解码似乎有效,因为查看文本,zip 中的文件名可以看到!但是当我尝试打开拉链时,它显示“档案意外结束”。现在感觉如此接近,因为我可以看到文件名......但也许我错过了文件中的一些结束字符?
  • 我在网站上使用的输出字符集是 UTF-8,我将文本文件保存为相同的...是吗?
  • @creative 它是多部分数据传输的一部分吗?还是所有数据集中在一起?
【解决方案2】:

我使用此处的代码来解决此问题。在线 base64 解码器不工作,但它通过这个代码 sn-p 工作。只需复制和粘贴,无需修改;

http://msdn.microsoft.com/en-us/library/system.convert.frombase64string%28v=vs.110%29.aspx

public void DecodeWithString() {
   System.IO.StreamReader inFile;    
   string base64String;

   try {
      char[] base64CharArray;
      inFile = new System.IO.StreamReader(inputFileName,
                              System.Text.Encoding.ASCII);
      base64CharArray = new char[inFile.BaseStream.Length];
      inFile.Read(base64CharArray, 0, (int)inFile.BaseStream.Length);
      base64String = new string(base64CharArray);
   }
   catch (System.Exception exp) {
      // Error creating stream or reading from it.
      System.Console.WriteLine("{0}", exp.Message);
      return;
   }

   // Convert the Base64 UUEncoded input into binary output. 
   byte[] binaryData;
   try {
      binaryData = 
         System.Convert.FromBase64String(base64String);
   }
   catch (System.ArgumentNullException) {
      System.Console.WriteLine("Base 64 string is null.");
      return;
   }
   catch (System.FormatException) {
      System.Console.WriteLine("Base 64 string length is not " +
         "4 or is not an even multiple of 4." );
      return;
   }

   // Write out the decoded data.
   System.IO.FileStream outFile;
   try {
      outFile = new System.IO.FileStream(outputFileName,
                                 System.IO.FileMode.Create,
                                 System.IO.FileAccess.Write);
      outFile.Write(binaryData, 0, binaryData.Length);
      outFile.Close();
   }
   catch (System.Exception exp) {
      // Error creating stream or writing to it.
      System.Console.WriteLine("{0}", exp.Message);
   }
}

【讨论】:

    猜你喜欢
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多