isislovecruft / python-gnupg

A modified version of python-gnupg, including security patches, extensive documentation, and extra features.
Other
424 stars 172 forks source link

How to encrypt files in batch #237

Open yunweiguo opened 6 years ago

yunweiguo commented 6 years ago

I want to encrypt two and more files in one times. the function is

'''

def encrypt_file gpg = gnupg.GPG(homedir=config.GNUPGHOME, binary='/usr/bin/gpg') with open(source_file) as f: data = f.read() fg = "***"

out = gpg.encrypt(data, fg, default_key=True,
                  passphrase=config.TIGER_GPG_PASS_PHRASE, armor=False, output=target_file)
with open(target_file, 'wb') as f:
    f.write(out.data)

'''

and below is how i encrypt them

`
a = 'a.xml' a_gpg = "{}.gpg".format(a) encrypt_file(a, a_gpg)

b = 'b.xml' b_gpg = "{}.gpg".format(b) encrypt_file(b, b_gpg) `

However the output files something looks bad, they garbled.. maybe a file garbled, maybe b file garbled. or no one , or both of them garbled... It seems the problem occur randomly.

But If I just only encrypt one file like `
a = 'a.xml' a_gpg = "{}.gpg".format(a) encrypt_file(a, a_gpg)

`

nothing goes wrong...

So is there someone can tell me how can I fix it