logo
  • Home
  • ソフトウェア
    • アタッシェケースアイコン
      アタッシェケース

      ファイル暗号化ツール(Windows)

    • MarkDown#Editorアイコン
      MarkDown#Editor

      Markdownデュアルエディタ(Windows)

    • OutlineTextアイコン
      OutLineText

      Markdownによるアウトライナー(macOS)

    • OutlineTextアイコン
      BossComing

      一瞬で偽デスクトップに差し替え(Windows)

  • 開発ツール
    • Png2WinIco

      PNGからWindowsICOファイル生成(Windows)

    • SHCode-JP-Zen-Haku

      プログラミング用等幅フォント(Windows, macOS)

    • 秀丸エディタ・日付挿入マクロ

      柔軟な日付挿入可能な「秀丸エディタ」専用マクロ

    • 秀丸エディタ・Markdown強調表示定義ファイル

      「秀丸エディタ」専用の強調表示定義ファイル

  • このサイトについて
  • ブログ
  1. Home
  2. Blog
2019年07月02日 17:33 更新

DotNetZipでEncryptionAlgorithm.WinZipAes256が選択できない

hibara

2016年8月7日 07:26 C# アタッシェケース プログラミング

Visual Studio C#で『アタッシェケース』の新版を開発中です。その中で、パスワードZIPファイルを作成するために、DotNetZipというライブラリを使っています。

DotNetZip-Logo

ところが、以下のコードのように設定しても、コンパイルエラーとなります。

private void Zipup()
{
  if (filesToZip.Count == 0)
  {
    System.Console.WriteLine("Nothing to do.");
    return;
  }

 using (var output= new ZipOutputStream(outputFileName))
 {
   output.Password = "VerySecret!";
   output.Encryption = EncryptionAlgorithm.WinZipAes256;

   foreach (string inputFileName in filesToZip)
   {
     System.Console.WriteLine("file: {0}", inputFileName);

     output.PutNextEntry(inputFileName);
     using (var input = File.Open(inputFileName, FileMode.Open, FileAccess.Read,
                                     FileShare.Read | FileShare.Write ))
     {
       byte[] buffer= new byte[2048];
       int n;
       while ((n= input.Read(buffer,0,buffer.Length)) > 0)
       {
         output.Write(buffer,0,n);
       }
      }
    }
  }

}

Visual Studioのインテリセンスを表示させてみても、
None
PkzipWeak
Unsupported
と、肝心の「AES」が出てきません。おかしいなあ、とDotNetZipのソースを見てみたら、defineで切られているではありませんか。

AESはdefineで切られている

おそらくパスワード付きZIPのAESは、アーカイバによって解凍できなかったりするので、こういう扱いなのでしょうか。実際、DotNetZipヘルプの「EncryptionAlgorithm 列挙体」には、こう書かれていました。

Values of WinZipAes128 and WinZipAes256 are not part of the Zip specification, but rather imply the use of a vendor-specific extension from WinZip. If you want to produce interoperable Zip archives, do not use these values. For example, if you produce a zip archive using WinZipAes256, you will be able to open it in Windows Explorer on Windows XP and Vista, but you will not be able to extract entries; trying this will lead to an “unspecified error”. For this reason, some people have said that a zip archive that uses WinZip’s AES encryption is not actually a zip archive at all. A zip archive produced this way will be readable with the WinZip tool (Version 11 and beyond).

WinZipAes128 値と WinZipAes256 値は zip 仕様に含まれていませんが、WinZip のベンダー固有の拡張を使用することを意味しています。相互運用可能な Zip アーカイブを生成するには、これらの値を使用しないでください。たとえば、WinZipAes256 を使用して zip アーカイブを生成する場合、Windows XP および Vista で Windows Explorer で開くことができますが、エントリーを解凍することはできません。解凍しようとすると、「未定義のエラー」となります。このため、WinZip の AES 暗号化を使用した zip アーカイブは、実際にはまったく zip アーカイブでないと言う人もいます。この方法で生成された zip アーカイブは、WinZip ツール (バージョン 11 以降) で読み込むことができます。

ですので、AESをどうしても使いたい場合は、Visual Studioの「条件付きコンパイルシンボル」に「AESCRYPTO」を追加します。

プロジェクトのプロパティを開く

プロジェクトのプロパティを開いて、

条件付きコンパイルシンボル

追加すると、コンパイルも通り、インテリセンスにも「WinZipAes128」「WinZipAes256」の値が表示されるようになります。


コメントする     返信コメントをキャンセル(閉じる)

メールアドレスが公開されることはありません。

これらの HTML タグと属性を使用できます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください。

HiBARA blog

日々の開発作業で気づいたこと共有を。同じところで躓いている人が、 検索で辿り着けたら良いな、というスタンスで記事を書くので不定期更新になります。

Post Categories

  • BizSpark (1)
  • C# (10)
  • C++ (2)
  • C++Builder (2)
  • C++Builder XE4 (1)
  • CoffeeScript (3)
  • DynamoDB (2)
  • Electron (1)
  • Inno Setup (3)
  • iPhone (1)
  • JavaScript (11)
  • jQuery (3)
  • Mac OSX (2)
  • Markdown (2)
  • MarkDown#Editor (5)
  • PHP (7)
  • Qt (5)
  • SHA-3 (2)
  • Smarty (2)
  • アタッシェケース (23)
  • など (2)
  • フォント (1)
  • プログラミング (33)
  • 未分類 (1)

Tags

  • DLL
  • exe
  • Inno Setup
  • NuGet
  • signtool
  • コードサイニング証明
  • サテライトアセンブリ
  • マージ
  • 光コラボレーション
  • 株式会社CL

© 2011-2023 M.Hibara

Facebook icon
Twitter icon
GitHub icon
Qiita icon