Exemple #1
0
 public ZipAESStream(Stream stream, ZipAESTransform transform, CryptoStreamMode mode)
     : base(stream, transform, mode)
 {
     _stream = stream;
     _transform = transform;
     _slideBuffer = new byte[0x400];
     _blockAndAuth = 0x1a;
     if (mode != CryptoStreamMode.Read)
     {
         throw new Exception("ZipAESStream only for read");
     }
 }
Exemple #2
0
 private Stream CreateAndInitDecryptionStream(Stream baseStream, ZipEntry entry)
 {
     if ((entry.Version < 50) || ((entry.Flags & 0x40) == 0))
     {
         PkzipClassicManaged managed = new PkzipClassicManaged();
         OnKeysRequired(entry.Name);
         if (!HaveKeys)
         {
             throw new ZipException("No password available for encrypted stream");
         }
         CryptoStream classicCryptoStream
             = new CryptoStream(baseStream, managed.CreateDecryptor(key, null), CryptoStreamMode.Read);
         CheckClassicPassword(classicCryptoStream, entry);
         return classicCryptoStream;
     }
     if (entry.Version != 0x33)
     {
         throw new ZipException("Decryption method not supported");
     }
     OnKeysRequired(entry.Name);
     if (!HaveKeys)
     {
         throw new ZipException("No password available for AES encrypted stream");
     }
     int aESSaltLen = entry.AESSaltLen;
     byte[] buffer = new byte[aESSaltLen];
     int num2 = baseStream.Read(buffer, 0, aESSaltLen);
     if (num2 != aESSaltLen)
     {
         throw new ZipException(string.Concat(new object[] { "AES Salt expected ", aESSaltLen, " got ", num2 }));
     }
     byte[] buffer2 = new byte[2];
     baseStream.Read(buffer2, 0, 2);
     int blockSize = entry.AESKeySize / 8;
     ZipAESTransform transform = new ZipAESTransform(rawPassword_, buffer, blockSize, false);
     byte[] pwdVerifier = transform.PwdVerifier;
     if ((pwdVerifier[0] != buffer2[0]) || (pwdVerifier[1] != buffer2[1]))
     {
         throw new Exception("Invalid password for AES");
     }
     return new ZipAESStream(baseStream, transform, CryptoStreamMode.Read);
 }