I ended up using Ionic.Zip
in Dot Net. Here is my html and javascript code
<div>
<input type="password" id="pass" placeholder="Set Password" />
<button type="submit" class="cutomDownloadCCDA">Zip</button>
</div>
<script>
$('.cutomDownloadCCDA').click(function(e) {
//window.location.href = "Home/Zip";// Simple Way
var password = $('#pass').val();
$('#downloadFrame').remove(); // This shouldn't fail if frame doesn't exist
$('body').append('<iframe id="downloadFrame" style="display:none"></iframe>');
$('#downloadFrame').attr('src', '/Home/Zip?password=' + password);
});
</script>
Here is the action Method of MVC
public void Zip(string password)
{
using (ZipFile zip = new ZipFile())
{
string xml = "Your XML Data";
var newStream = new MemoryStream();
var newWriter = XmlWriter.Create(newStream);
newWriter.WriteRaw(xml);
newStream.Position = 0;
newWriter.Flush();
newStream.Seek(0, SeekOrigin.Begin);
// Ist File
ZipEntry e = zip.AddEntry("test.xml", newStream);
e.Password = password;
e.Encryption = EncryptionAlgorithm.WinZipAes256;
// 2nd File
//ZipEntry f2 = zip.AddEntry("test1.xml", newStream);
//f2.Password = "456";
//f2.Encryption = EncryptionAlgorithm.WinZipAes256;
Response.ContentType = "application/zip";
Response.AddHeader("Content-Disposition", "attachment;filename=somefile.zip");
zip.Save(Response.OutputStream);
}
}