python bindings: howto examples
* Made sure all example scripts meet PEP8 compliance. * Required fixing approx. a dozen of them in minor ways.
This commit is contained in:
parent
66c2a99422
commit
cacca62d06
@ -32,10 +32,10 @@ if len(sys.argv) == 3:
|
||||
newfile = sys.argv[2]
|
||||
elif len(sys.argv) == 2:
|
||||
ciphertext = sys.argv[1]
|
||||
newfile = input("Enter path and filename of file to save decrypted data to: ")
|
||||
newfile = input("Enter path and filename to save decrypted data to: ")
|
||||
else:
|
||||
ciphertext = input("Enter path and filename of encrypted file: ")
|
||||
newfile = input("Enter path and filename of file to save decrypted data to: ")
|
||||
newfile = input("Enter path and filename to save decrypted data to: ")
|
||||
|
||||
with open(ciphertext, "rb") as cfile:
|
||||
try:
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,9 +27,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
|
||||
"""
|
||||
Encrypts a file to a specified key. If entering both the key and the filename
|
||||
on the command line, the key must be entered first.
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,9 +27,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
|
||||
"""
|
||||
Signs and encrypts a file to a specified key. If entering both the key and the
|
||||
filename on the command line, the key must be entered first.
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
from groups import group_lists
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,10 +28,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
from groups import group_lists
|
||||
|
||||
"""
|
||||
Uses the groups module to encrypt to multiple recipients.
|
||||
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
from groups import group_lists
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,10 +28,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
from groups import group_lists
|
||||
|
||||
"""
|
||||
Uses the groups module to encrypt to multiple recipients.
|
||||
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
from groups import group_lists
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,10 +28,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import sys
|
||||
from groups import group_lists
|
||||
|
||||
"""
|
||||
Uses the groups module to encrypt to multiple recipients.
|
||||
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,10 +28,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
print("""
|
||||
This script exports one or more public keys.
|
||||
""")
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,10 +28,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
print("""
|
||||
This script exports one or more public keys in minimised form.
|
||||
""")
|
||||
|
@ -3,6 +3,11 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,11 +29,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
print("""
|
||||
This script exports one or more secret keys.
|
||||
|
||||
|
@ -3,6 +3,12 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,12 +30,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import os
|
||||
import os.path
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
print("""
|
||||
This script exports one or more secret keys as both ASCII armored and binary
|
||||
file formats, saved in files within the user's GPG home directory.
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,10 +28,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
print("""
|
||||
This script exports one or more public keys.
|
||||
""")
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import gpg
|
||||
import os.path
|
||||
import requests
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,17 +28,10 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import gpg
|
||||
import os.path
|
||||
import requests
|
||||
|
||||
print("""
|
||||
This script imports one or more public keys from the SKS keyservers.
|
||||
""")
|
||||
|
||||
import gpg
|
||||
import requests
|
||||
|
||||
c = gpg.Context()
|
||||
url = "https://sks-keyservers.net/pks/lookup"
|
||||
pattern = input("Enter the pattern to search for key or user IDs: ")
|
||||
|
@ -3,6 +3,10 @@
|
||||
|
||||
from __future__ import absolute_import, division, unicode_literals
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
# Copyright (C) 2018 Ben McGinnes <ben@gnupg.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
@ -24,10 +28,6 @@ from __future__ import absolute_import, division, unicode_literals
|
||||
# Lesser General Public along with this program; if not, see
|
||||
# <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
intro = """
|
||||
This script creates a temporary directory to use as a homedir for
|
||||
testing key generation tasks with the correct permissions, along
|
||||
@ -54,6 +54,13 @@ message telling you to specify a new directory name. There is no
|
||||
default directory name.
|
||||
"""
|
||||
|
||||
ciphers256 = "TWOFISH CAMELLIA256 AES256"
|
||||
ciphers192 = "CAMELLIA192 AES192"
|
||||
ciphers128 = "CAMELLIA128 AES"
|
||||
ciphersBad = "BLOWFISH IDEA CAST5 3DES"
|
||||
digests = "SHA512 SHA384 SHA256 SHA224 RIPEMD160 SHA1"
|
||||
compress = "ZLIB BZIP2 ZIP Uncompressed"
|
||||
|
||||
gpgconf = """# gpg.conf settings for key generation:
|
||||
expert
|
||||
allow-freeform-uid
|
||||
@ -63,11 +70,11 @@ tofu-default-policy unknown
|
||||
enable-large-rsa
|
||||
enable-dsa2
|
||||
cert-digest-algo SHA512
|
||||
default-preference-list TWOFISH CAMELLIA256 AES256 CAMELLIA192 AES192 CAMELLIA128 AES BLOWFISH IDEA CAST5 3DES SHA512 SHA384 SHA256 SHA224 RIPEMD160 SHA1 ZLIB BZIP2 ZIP Uncompressed
|
||||
personal-cipher-preferences TWOFISH CAMELLIA256 AES256 CAMELLIA192 AES192 CAMELLIA128 AES BLOWFISH IDEA CAST5 3DES
|
||||
personal-digest-preferences SHA512 SHA384 SHA256 SHA224 RIPEMD160 SHA1
|
||||
personal-compress-preferences ZLIB BZIP2 ZIP Uncompressed
|
||||
"""
|
||||
default-preference-list {0} {1} {2} {3} {4} {5}
|
||||
personal-cipher-preferences {0} {1} {2} {3}
|
||||
personal-digest-preferences {4}
|
||||
personal-compress-preferences {5}
|
||||
""".format(ciphers256, ciphers192, ciphers128, ciphersBad, digests, compress)
|
||||
|
||||
agentconf = """# gpg-agent.conf settings for key generation:
|
||||
default-cache-ttl 300
|
||||
|
Loading…
Reference in New Issue
Block a user