Exemple #1
0
        static public bool VerifyPassword(string filePath, string password)
        {
            try
            {
                using (var zip = new ZipWrapper())
                {
                    zip.OpenZip(filePath);

                    Logger.LogInfo(string.Format("File {0} PasswordProtect status: {1}", filePath, zip.PasswordProtect.ToString()));
                    Logger.LogInfo(string.Format("File {0} Encryption value: {1}", filePath, zip.Encryption.ToString()));

                    // PasswordProtect == old style zip 2.0 encryption
                    // Encryption > 0 indicates 'modern' strong encryption has been used
                    if (zip.PasswordProtect || (zip.Encryption > 0))
                    {
                        zip.SetPassword(password);
                        return zip.VerifyPassword();
                    }
                }
                return false;
            }
            catch (Exception ex)
            {
                Logger.LogDebug(ex);
                throw new Exception("Unable to process zip file:" + filePath);
            }
        }