Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:05:29+00:00 2026-06-15T21:05:29+00:00

I have an use case where I need to strip decryption of password protected

  • 0

I have an use case where I need to strip decryption of password protected zip file attached to an email, and replace it with the same zip file unencrypted. What I have so far:

import zipfile
import StringIO

...

if part.get_content_type() == "application/zip":
    encrypted_string = part.get_payload().decode("base64")
    encrypted_zip = zipfile.ZipFile(StringIO(encrypted_string))
    encrypted_zip.setpassword("password")

I know that the zip file is now decrypted as I can do encrypted_zip.namelist() and it works. Now that I have regular zip in the var encrypted_zip, I would just like to base64 encode it and replace the payload of the current attachment and move forward to next attachment. However, ZipFile does not have “.to_string()” method which i could use to re-encode it.

How do I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:05:30+00:00Added an answer on June 15, 2026 at 9:05 pm

    You can create a temporary archive to get rid of the password :

    import zipfile
    import StringIO
    
    
    path = "dev.zip"   
    encrypted_zip = zipfile.ZipFile( path  )
    encrypted_zip.setpassword("pass")
    print encrypted_zip.namelist()
    
    with zipfile.ZipFile('spam.zip', 'w') as myzip:
        for nested_file in encrypted_zip.namelist():
            myzip.write(encrypted_zip.read(nested_file))
    

    The script copy files for the password-protected archive ‘dev.zip’ into the uncrypted archive ‘spam.zip’. ( do not forget to destroy the archive after).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a use case where I need to call a (non-static) method in
I have a use case where I only need to store certain fields to
I have a strong use case for pre-allocating all the memory I need upfront
I have this use case of an xml file with input like Input: <abc
I am pretty new to android. I have a use case where I need
In Zend Framework, I have a common use case where I need to propagate
I have a use case where I need to export this specific piece of
I have a use case where i need to read the content of the
I have a use case where I need to send some information from my
I have a use case where I need to iterate over the Vector elements

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.