This is Python 3 module and CLI to encrypt file for DIDWW API 3.
File encrypted with mode sandbox
could be uploaded to POST https://sandbox-api.didww.com/v3/encrypted_files
.
File encrypted with mode production
could be uploaded to POST https://api.didww.com/v3/encrypted_files
.
see DIDWW Documentation for details.
Python >=3.6
pip install didww_encrypt
from didww_encrypt import Encrypt, MODE_PRODUCTION
with open("doc.pdf", mode="rb") as f:
data = f.read()
enc = Encrypt.new(MODE_PRODUCTION)
enc_data = enc.encrypt(data)
enc_filename = "doc.pdf.enc"
with open(enc_filename, mode="wb") as f:
f.write(enc_data)
print(f"encrypted file saved: {enc_filename}")
print(f"fingerprint: {enc.fingerprint}")
usage: didww_encrypt [-h] [-i [INPUT]] [-o [OUTPUT]] [-f] (-m [{sandbox,production}] | -u [URI])
Encrypt file for DIDWW API 3
optional arguments:
-h, --help show this help message and exit
-i [INPUT], --input [INPUT]
use input pipe when not passed
-o [OUTPUT], --output [OUTPUT]
use output pipe when not passed
-f, --fingerprint return fingerprint for public keys
-m [{sandbox,production}], --mode [{sandbox,production}]
which DIDWW server use for public keys fetching
-u [URI], --uri [URI]
custom URI for public keys fetching
You can pass input and output files as params
$ didww_encrypt -i ./doc.pdf -o ./doc.pdf.enc -m sandbox
Or using pipe
$ cat ./doc.pdf | didww_encrypt -m production > ./doc.pdf.enc
Also script could be run via python -m
$ python -m didww_encrypt -i ./doc.pdf -o ./doc.pdf.enc -m production
$ cat ./doc.pdf | python -m didww_encrypt -m sandbox > ./doc.pdf.enc
To print fingerprint use -f
option instead of -i
$ didww_encrypt -f -m sandbox
c74684d7863639169c21c4d04747f8d6fa05cfe3:::7c56fd5d2e1f2ada18765d936e74712037aea7eb
Or you can save it to a file
$ didww_encrypt -f -m sandbox -o fingerprint.txt
Keep in mind that shell script returns fingerprint with newline which should be omitted when send it to /v3/encrypted_files
.
both shell script and module function Encrypt.new
respects http_proxy
env variable when fetching public keys.
http_proxy="http://myproxy.example.com:1234" didww_encrypt -m sandbox
pip install -r requirements.txt
pip install -r tests/requirements.txt
python -m unittest -v
coverage run -m unittest -v
flake8 . --count --show-source --statistics
black .