internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length)
        {
            this.stream          = stream;
            totalBytesLeftToRead = length;

            rijndael = CreateRijndael(winzipAesEncryptionData);
        }
        internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length)
        {
            this.stream = stream;
            totalBytesLeftToRead = length;

            rijndael = CreateRijndael(winzipAesEncryptionData);
        }
 private IBufferedCipher CreateRijndael(WinzipAesEncryptionData winzipAesEncryptionData)
 {
     var blockCipher = new BufferedBlockCipher(new RijndaelEngine());
     var param = new KeyParameter(winzipAesEncryptionData.KeyBytes);
     blockCipher.Init(true, param);
     return blockCipher;
 }
Exemplo n.º 4
0
 internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length)
 {
     this.stream = stream;
     this.totalBytesLeftToRead = length;
     this.cipher = this.CreateCipher(winzipAesEncryptionData);
     byte[] rgbIV = new byte[0x10];
     this.transform = this.cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, rgbIV);
 }
        private IBufferedCipher CreateRijndael(WinzipAesEncryptionData winzipAesEncryptionData)
        {
            var blockCipher = new BufferedBlockCipher(new RijndaelEngine());
            var param       = new KeyParameter(winzipAesEncryptionData.KeyBytes);

            blockCipher.Init(true, param);
            return(blockCipher);
        }
 internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length)
 {
     this.stream = stream;
     this.totalBytesLeftToRead = length;
     this.cipher = this.CreateCipher(winzipAesEncryptionData);
     byte[] rgbIV = new byte[0x10];
     this.transform = this.cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, rgbIV);
 }
Exemplo n.º 7
0
 private SymmetricAlgorithm CreateCipher(WinzipAesEncryptionData winzipAesEncryptionData)
 {
     RijndaelManaged cipher = new RijndaelManaged();
     cipher.BlockSize = BLOCK_SIZE_IN_BYTES * 8;
     cipher.KeySize = winzipAesEncryptionData.KeyBytes.Length * 8;
     cipher.Mode = CipherMode.ECB;
     cipher.Padding = PaddingMode.None;
     return cipher;
 }
Exemplo n.º 8
0
        private SymmetricAlgorithm CreateCipher(WinzipAesEncryptionData winzipAesEncryptionData)
        {
            RijndaelManaged managed = new RijndaelManaged();

            managed.BlockSize = 0x80;
            managed.KeySize   = winzipAesEncryptionData.KeyBytes.Length * 8;
            managed.Mode      = CipherMode.ECB;
            managed.Padding   = PaddingMode.None;
            return(managed);
        }
Exemplo n.º 9
0
        internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length)
        {
            this.stream = stream;
            totalBytesLeftToRead = length;

            cipher = CreateCipher(winzipAesEncryptionData);

            var iv = new byte[BLOCK_SIZE_IN_BYTES];
            transform = cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, iv);
        }
Exemplo n.º 10
0
        private SymmetricAlgorithm CreateCipher(WinzipAesEncryptionData winzipAesEncryptionData)
        {
            var cipher = Aes.Create();

            cipher.BlockSize = BLOCK_SIZE_IN_BYTES * 8;
            cipher.KeySize   = winzipAesEncryptionData.KeyBytes.Length * 8;
            cipher.Mode      = CipherMode.ECB;
            cipher.Padding   = PaddingMode.None;
            return(cipher);
        }
Exemplo n.º 11
0
        internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length)
        {
            this._stream          = stream;
            _totalBytesLeftToRead = length;

            _cipher = CreateCipher(winzipAesEncryptionData);

            var iv = new byte[BLOCK_SIZE_IN_BYTES];

            _transform = _cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, iv);
        }
Exemplo n.º 12
0
        private SymmetricAlgorithm CreateCipher(WinzipAesEncryptionData winzipAesEncryptionData)
        {
#if !SILVERLIGHT && !PORTABLE
            RijndaelManaged cipher = new RijndaelManaged();
            cipher.BlockSize = BLOCK_SIZE_IN_BYTES * 8;
            cipher.KeySize = winzipAesEncryptionData.KeyBytes.Length * 8;
            cipher.Mode = CipherMode.ECB;
            cipher.Padding = PaddingMode.None;
            return cipher;
#else
            throw new NotSupportedException("Cannot decrypt Winzip AES with Silverlight or WP7.");
#endif
        }
Exemplo n.º 13
0
        private SymmetricAlgorithm CreateCipher(WinzipAesEncryptionData winzipAesEncryptionData)
        {
#if !SILVERLIGHT && !PORTABLE
            RijndaelManaged cipher = new RijndaelManaged();
            cipher.BlockSize = BLOCK_SIZE_IN_BYTES * 8;
            cipher.KeySize   = winzipAesEncryptionData.KeyBytes.Length * 8;
            cipher.Mode      = CipherMode.ECB;
            cipher.Padding   = PaddingMode.None;
            return(cipher);
#else
            throw new NotSupportedException("Cannot decrypt Winzip AES with Silverlight or WP7.");
#endif
        }
Exemplo n.º 14
0
        internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length,
                                       CryptoMode mode)
        {
            this.mode = mode;
            this.stream = stream;
            totalBytesLeftToRead = length;

            hmac = new HMACSHA1(winzipAesEncryptionData.IvBytes);

            cipher = CreateCipher(winzipAesEncryptionData);

            var iv = new byte[BLOCK_SIZE_IN_BYTES];
            transform = cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, iv);

            //if (_mode == CryptoMode.Encrypt)
            //{
            //    _iobuf = new byte[2048];
            //    _PendingWriteBlock = new byte[BLOCK_SIZE_IN_BYTES];
            //}
        }
Exemplo n.º 15
0
        internal WinzipAesCryptoStream(Stream stream, WinzipAesEncryptionData winzipAesEncryptionData, long length,
                                       CryptoMode mode)
        {
            //this.mode = mode;
            this.stream          = stream;
            totalBytesLeftToRead = length;

            hmac = new HMACSHA1(winzipAesEncryptionData.IvBytes);

            cipher = CreateCipher(winzipAesEncryptionData);

            var iv = new byte[BLOCK_SIZE_IN_BYTES];

            transform = cipher.CreateEncryptor(winzipAesEncryptionData.KeyBytes, iv);

            //if (_mode == CryptoMode.Encrypt)
            //{
            //    _iobuf = new byte[2048];
            //    _PendingWriteBlock = new byte[BLOCK_SIZE_IN_BYTES];
            //}
        }
Exemplo n.º 16
0
        private void LoadHeader(ZipFileEntry entryHeader, Stream stream)
        {
            if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.Encrypted))
            {
                if (!entryHeader.IsDirectory &&
                    entryHeader.CompressedSize == 0 &&
                    FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
                {
                    throw new NotSupportedException(
                              "SharpCompress cannot currently read non-seekable Zip Streams with encrypted data that has been written in a non-seekable manner.");
                }
                if (password == null)
                {
                    throw new CryptographicException("No password supplied for encrypted zip.");
                }
                if (entryHeader.CompressionMethod != ZipCompressionMethod.WinzipAes)
                {
                    byte[] buffer = new byte[12];
                    stream.Read(buffer, 0, 12);
                    entryHeader.PkwareTraditionalEncryptionData = PkwareTraditionalEncryptionData.ForRead(password,
                                                                                                          entryHeader,
                                                                                                          buffer);
                    entryHeader.CompressedSize -= 12;
                }
                else
                {
#if NO_CRYPTO
                    throw new NotSupportedException("Cannot decrypt Winzip AES with Silverlight or WP7.");
#else
                    var data = entryHeader.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes);
                    WinzipAesKeySize keySize = (WinzipAesKeySize)data.DataBytes[4];

                    byte[] salt = new byte[WinzipAesEncryptionData.KeyLengthInBytes(keySize) / 2];
                    byte[] passwordVerifyValue = new byte[2];
                    stream.Read(salt, 0, salt.Length);
                    stream.Read(passwordVerifyValue, 0, 2);
                    entryHeader.WinzipAesEncryptionData = new WinzipAesEncryptionData(keySize, salt, passwordVerifyValue,
                                                                                      password);
                    entryHeader.CompressedSize -= (uint)(salt.Length + 2);
#endif
                }
            }
            if (entryHeader.IsDirectory)
            {
                return;
            }
            //if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
            //{
            //    entryHeader.PackedStream = new ReadOnlySubStream(stream);
            //}
            //else
            //{
            switch (mode)
            {
            case StreamingMode.Seekable:
            {
                entryHeader.DataStartPosition = stream.Position;
                stream.Position += entryHeader.CompressedSize;
            }
            break;

            case StreamingMode.Streaming:
            {
                entryHeader.PackedStream = stream;
            }
            break;

            default:
            {
                throw new InvalidFormatException("Invalid StreamingMode");
            }
            }
            //}
        }
Exemplo n.º 17
0
        private void LoadHeader(ZipFileEntry entryHeader, Stream stream)
        {
            if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.Encrypted))
            {
                if (!entryHeader.IsDirectory && entryHeader.CompressedSize == 0 &&
                    FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
                {
                    throw new NotSupportedException("SharpCompress cannot currently read non-seekable Zip Streams with encrypted data that has been written in a non-seekable manner.");
                }

                if (_password == null)
                {
                    throw new CryptographicException("No password supplied for encrypted zip.");
                }

                entryHeader.Password = _password;

                if (entryHeader.CompressionMethod == ZipCompressionMethod.WinzipAes)
                {
                    ExtraData data = entryHeader.Extra.SingleOrDefault(x => x.Type == ExtraDataType.WinZipAes);
                    if (data != null)
                    {
                        var keySize = (WinzipAesKeySize)data.DataBytes[4];

                        var salt = new byte[WinzipAesEncryptionData.KeyLengthInBytes(keySize) / 2];
                        var passwordVerifyValue = new byte[2];
                        stream.Read(salt, 0, salt.Length);
                        stream.Read(passwordVerifyValue, 0, 2);
                        entryHeader.WinzipAesEncryptionData =
                            new WinzipAesEncryptionData(keySize, salt, passwordVerifyValue, _password);

                        entryHeader.CompressedSize -= (uint)(salt.Length + 2);
                    }
                }
            }

            if (entryHeader.IsDirectory)
            {
                return;
            }

            //if (FlagUtility.HasFlag(entryHeader.Flags, HeaderFlags.UsePostDataDescriptor))
            //{
            //    entryHeader.PackedStream = new ReadOnlySubStream(stream);
            //}
            //else
            //{
            switch (_mode)
            {
            case StreamingMode.Seekable:
            {
                entryHeader.DataStartPosition = stream.Position;
                stream.Position += entryHeader.CompressedSize;
                break;
            }

            case StreamingMode.Streaming:
            {
                entryHeader.PackedStream = stream;
                break;
            }

            default:
            {
                throw new InvalidFormatException("Invalid StreamingMode");
            }
            }

            //}
        }
Exemplo n.º 18
0
 private SymmetricAlgorithm CreateCipher(WinzipAesEncryptionData winzipAesEncryptionData)
 {
     throw new NotSupportedException("Cannot decrypt Winzip AES with Silverlight or WP7.");
 }
 private SymmetricAlgorithm CreateCipher(WinzipAesEncryptionData winzipAesEncryptionData)
 {
     RijndaelManaged managed = new RijndaelManaged();
     managed.BlockSize = 0x80;
     managed.KeySize = winzipAesEncryptionData.KeyBytes.Length * 8;
     managed.Mode = CipherMode.ECB;
     managed.Padding = PaddingMode.None;
     return managed;
 }