internal override EncoderNode CreateEncoder() { var passwordAccess = default(PasswordAccessor); var encryptionKey = default(byte[]); var passwordBytes = default(byte[]); try { passwordAccess = mPassword.GetPassword(); passwordBytes = Encoding.Unicode.GetBytes(passwordAccess); encryptionKey = Reader.AesArchiveDecoder.InitKey(mSlowdown, mSeed.mSalt, passwordBytes); using (var aes = System.Security.Cryptography.Aes.Create()) { aes.Mode = System.Security.Cryptography.CipherMode.CBC; aes.Padding = System.Security.Cryptography.PaddingMode.None; return(new AesEncoderNode(aes.CreateEncryptor(encryptionKey, mSeed.mSeed16))); } } finally { passwordAccess.Dispose(); Utilities.ClearBuffer(ref passwordBytes); Utilities.ClearBuffer(ref encryptionKey); } }
private void Initialize(Stream input, byte[] info, PasswordStorage password, long limit) { mBuffer = new byte[4 << 10]; 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[] pass = null; byte[] key = null; try { using (var accessor = password.GetPassword()) pass = Encoding.Unicode.GetBytes(accessor); key = InitKey(numCyclesPower, salt, pass); using (var aes = Aes.Create()) { aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.None; mDecoder = aes.CreateDecryptor(key, seed); } } finally { Utilities.ClearBuffer(ref pass); Utilities.ClearBuffer(ref key); } }
private void Initialize(Stream input, byte[] info, PasswordStorage password, long limit) { mBuffer = new byte[4 << 10]; 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[] pass = null; byte[] key = null; try { using (var accessor = password.GetPassword()) pass = Encoding.Unicode.GetBytes(accessor); key = InitKey(numCyclesPower, salt, pass); using (var aes = Aes.Create()) { aes.Mode = CipherMode.CBC; aes.Padding = PaddingMode.None; mDecoder = aes.CreateDecryptor(key, seed); } } finally { Utilities.ClearBuffer(ref pass); Utilities.ClearBuffer(ref key); } }