/// <summary> /// Verify the password on a zip file. /// </summary> /// /// <remarks> /// <para> /// Keep in mind that passwords in zipfiles are applied to /// zip entries, not to the entire zip file. So testing a /// zipfile for a particular password doesn't work in the /// general case. On the other hand, it's often the case /// that a single password will be used on all entries in a /// zip file. This method works for that case. /// </para> /// <para> /// There is no way to check a password without doing the /// decryption. So this code decrypts and extracts the given /// zipfile into <see cref="System.IO.Stream.Null"/> /// </para> /// </remarks> /// /// <param name="zipFileName">The filename to of the zip file to fix.</param> /// /// <param name="password">The password to check.</param> /// /// <returns>a bool indicating whether the password matches.</returns> internal static bool CheckZipPassword(string zipFileName, string password) { string fullPath = GetFullPath(zipFileName); var file = FileSystem.Current.GetFileFromPathAsync(fullPath).ExecuteSync(); if (file == null) { throw new FileNotFoundException(string.Format("That file ({0}) does not exist!", zipFileName)); } using (var stream = file.OpenAsync(FileAccess.Read).ExecuteSync()) { return(ZipFile.CheckZipPassword(stream, password)); } }
/// <summary> /// A COM-friendly wrapper for the static method <see cref="ZipFile.CheckZipPassword(string,string)"/>. /// </summary> /// /// <param name="filename">The filename to of the zip file to check.</param> /// /// <param name="password">The password to check.</param> /// /// <returns>true if the named zip file checks OK. Otherwise, false. </returns> public bool CheckZipPassword(string filename, string password) { return(ZipFile.CheckZipPassword(filename, password)); }
/// <summary> /// Verify the password on a zip file. /// </summary> /// /// <remarks> /// <para> /// Keep in mind that passwords in zipfiles are applied to /// zip entries, not to the entire zip file. So testing a /// zipfile for a particular password doesn't work in the /// general case. On the other hand, it's often the case /// that a single password will be used on all entries in a /// zip file. This method works for that case. /// </para> /// <para> /// There is no way to check a password without doing the /// decryption. So this code decrypts and extracts the given /// zipfile into <see cref="System.IO.Stream.Null"/> /// </para> /// </remarks> /// /// <param name="zipFileName">The filename to of the zip file to fix.</param> /// /// <param name="password">The password to check.</param> /// /// <returns>a bool indicating whether the password matches.</returns> public static bool CheckZipPassword(Stream zipFileStream, string password) { return(ZipFile.CheckZipPassword(zipFileStream, password)); }