コード例 #1
1
        public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
        {
            mStream = input;
            mLimit = limit;

            // The 7z AES encoder/decoder classes do not perform padding, instead they require the input stream to provide a multiple of 16 bytes.
            // If the exception below is thrown this means the 7z file is either corrupt or a newer 7z version has been published and we haven't updated yet.
            if (((uint)input.Length & 15) != 0)
                throw new NotSupportedException("7z requires AES streams to be properly padded.");

            int numCyclesPower;
            byte[] salt, seed;
            Init(info, out numCyclesPower, out salt, out seed);

            byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
            byte[] key = InitKey(numCyclesPower, salt, password);

            using (var aes = Aes.Create())
            {
                aes.Mode = CipherMode.CBC;
                aes.Padding = PaddingMode.None;
                mDecoder = aes.CreateDecryptor(key, seed);
            }

            mBuffer = new byte[4 << 10];
        }
コード例 #2
0
        public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
        {
            if (pass.CryptoGetTextPassword() == null)
            {
                throw new SharpCompress.Common.CryptographicException("Encrypted 7Zip archive has no password specified.");
            }

            mStream = input;
            mLimit  = limit;

            if (((uint)input.Length & 15) != 0)
            {
                throw new NotSupportedException("AES decoder does not support padding.");
            }

            Init(info, out int numCyclesPower, out byte[] salt, out byte[] seed);

            byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
            byte[]? key = InitKey(numCyclesPower, salt, password);
            if (key == null)
            {
                throw new InvalidOperationException("Initialized with null key");
            }

            using (var aes = Aes.Create())
            {
                aes.Mode    = CipherMode.CBC;
                aes.Padding = PaddingMode.None;
                mDecoder    = aes.CreateDecryptor(key, seed);
            }

            mBuffer = new byte[4 << 10];
        }
コード例 #3
0
        public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
        {
            mStream = input;
            mLimit  = limit;

            if (((uint)input.Length & 15) != 0)
            {
                throw new NotSupportedException("AES decoder does not support padding.");
            }

            int numCyclesPower;

            byte[] salt, seed;
            Init(info, out numCyclesPower, out salt, out seed);

            byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
            byte[] key      = InitKey(numCyclesPower, salt, password);

            using (var aes = Aes.Create())
            {
                aes.Mode    = CipherMode.CBC;
                aes.Padding = PaddingMode.None;
                mDecoder    = aes.CreateDecryptor(key, seed);
            }

            mBuffer = new byte[4 << 10];
        }
コード例 #4
0
        public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
        {
            mStream = input;
            mLimit  = limit;

            // The 7z AES encoder/decoder classes do not perform padding, instead they require the input stream to provide a multiple of 16 bytes.
            // If the exception below is thrown this means the 7z file is either corrupt or a newer 7z version has been published and we haven't updated yet.
            if (((uint)input.Length & 15) != 0)
            {
                throw new NotSupportedException("7z requires AES streams to be properly padded.");
            }

            int numCyclesPower;

            byte[] salt, seed;
            Init(info, out numCyclesPower, out salt, out seed);

            byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
            byte[] key      = InitKey(numCyclesPower, salt, password);

            using (var aes = Aes.Create())
            {
                aes.Mode    = CipherMode.CBC;
                aes.Padding = PaddingMode.None;
                mDecoder    = aes.CreateDecryptor(key, seed);
            }

            mBuffer = new byte[4 << 10];
        }
コード例 #5
0
 public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
 {
     int num;
     byte[] buffer;
     byte[] buffer2;
     this.mStream = input;
     this.mLimit = limit;
     if ((((uint) input.Length) & 15) != 0)
     {
         throw new NotSupportedException("AES decoder does not support padding.");
     }
     this.Init(info, out num, out buffer, out buffer2);
     byte[] bytes = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
     byte[] rgbKey = this.InitKey(num, buffer, bytes);
     using (Rijndael rijndael = Rijndael.Create())
     {
         rijndael.Mode = CipherMode.CBC;
         rijndael.Padding = PaddingMode.None;
         this.mDecoder = rijndael.CreateDecryptor(rgbKey, buffer2);
     }
     this.mBuffer = new byte[0x1000];
 }
コード例 #6
0
        public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
        {
            int num;

            byte[] buffer;
            byte[] buffer2;
            this.mStream = input;
            this.mLimit  = limit;
            if ((((uint)input.Length) & 15) != 0)
            {
                throw new NotSupportedException("AES decoder does not support padding.");
            }
            this.Init(info, out num, out buffer, out buffer2);
            byte[] bytes  = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
            byte[] rgbKey = this.InitKey(num, buffer, bytes);
            using (Rijndael rijndael = Rijndael.Create())
            {
                rijndael.Mode    = CipherMode.CBC;
                rijndael.Padding = PaddingMode.None;
                this.mDecoder    = rijndael.CreateDecryptor(rgbKey, buffer2);
            }
            this.mBuffer = new byte[0x1000];
        }
コード例 #7
0
        public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
        {
            mStream = input;
            mLimit = limit;

            if (((uint) input.Length & 15) != 0)
                throw new NotSupportedException("AES decoder does not support padding.");

            int numCyclesPower;
            byte[] salt, seed;
            Init(info, out numCyclesPower, out salt, out seed);

            byte[] password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
            byte[] key = InitKey(numCyclesPower, salt, password);

            using (var aes = Aes.Create())
            {
                aes.Mode = CipherMode.CBC;
                aes.Padding = PaddingMode.None;
                mDecoder = aes.CreateDecryptor(key, seed);
            }

            mBuffer = new byte[4 << 10];
        }