Skip to main content

A simple-to-use file encryption script

Project description

kapak - A simple-to-use file encryption script

tests codecov GitHub GitHub last commit (branch) GitHub release (latest SemVer) GitHub Repo stars GitHub forks

Kapak is a simple-to-use file encryption script/library.
It uses AES_256_CBC as its encryption cipher.

If you are wondering what kapak means, it means mold.

Installation

Installing with pip:

pip install kapak

CLI Usage

kapak [global options] [command] [command options] [input]
kapak [encrypt | e] [options] [input]
kapak [decrypt | d] [options] [input]

Encrypt file

$ kapak encrypt -o ./image.jpg.kpk ./image.jpg
Enter password:
Confirm password:
■■■■■■■■■■ 100%
$ kapak decrypt -o ./image.jpg ./image.jpg.kpk
Enter password:
■■■■■■■■■■ 100%

Encrypt stdin

$ echo 'secret stuff' | kapak encrypt | base64
Enter password:
Confirm password:
AAAAbWth...t/ILJW/v
$ echo 'AAAAbWth...t/ILJW/v' | base64 --decode | kapak decrypt
Enter password:
secret stuff
$ cat ./text.txt | kapak encrypt -b 1024 > ./text.txt.kpk
Enter password:
Confirm password:
$ kapak decrypt -b 1024 ./text.txt.kpk > ./text.txt
Enter password:

Password file

$ echo 'P@ssw0rd' > ./password.txt
$ kapak encrypt -p ./password.txt -o ./image.jpg.kpk ./image.jpg
■■■■■■■■■■ 100%
$ kapak decrypt -p ./password.txt -o ./image.jpg ./image.jpg.kpk
■■■■■■■■■■ 100%

Integration

Encrypt file

from pathlib import Path
from kapak.aes import encrypt

input_file = Path("image.jpg")
output_file = Path("image.jpg.kpk")

with input_file.open("rb") as src, output_file.open("wb") as dst:
    total_len = input_file.stat().st_size
    progress = 0
    for chunk_len in encrypt(src, dst, "P@ssw0rd"):
        progress += chunk_len
        print(f"{progress}/{total_len}")

kapak.aes.encrypt is a generator. It yields the length of encrypted data on every iteration.

from pathlib import Path
from itertools import accumulate
from kapak.aes import decrypt

input_file = Path("image.jpg.kpk")
output_file = Path("image.jpg")

with input_file.open("rb") as src, output_file.open("wb") as dst:
    total_len = input_file.stat().st_size
    for progress in accumulate(decrypt(src, dst, "P@ssw0rd")):
        print(f"{progress}/{total_len}")

kapak.aes.decrypt is a generator. It yields the length of decrypted data on every iteration.

Encrypt stdin

import sys
from io import BytesIO
from kapak.aes import encrypt

with BytesIO() as dst:
    for _ in encrypt(
        src=sys.stdin.buffer,
        dst=dst,
        password="P@ssw0rd",
        buffer_size=1024
    ):
        pass
    encrypted_data = dst.getvalue()
    print(encrypted_data.hex())

Encrypt anything

from io import BytesIO
from kapak.aes import encrypt

anything = b"anything"

with BytesIO(anything) as src, BytesIO() as dst:
    for _ in encrypt(
        src=src,
        dst=dst,
        password="P@ssw0rd",
        buffer_size=1024
    ):
        pass
    encrypted_data = dst.getvalue()
    print(encrypted_data.hex())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kapak-4.0.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distribution

kapak-4.0.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file kapak-4.0.0.tar.gz.

File metadata

  • Download URL: kapak-4.0.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for kapak-4.0.0.tar.gz
Algorithm Hash digest
SHA256 19455acfad054932ef7e6d73c7b471b589304503c67e2c4e8fca7b830c236188
MD5 9633d9b9baffa438e50cbe66b6b45e4a
BLAKE2b-256 dc6784c2f6ec77f35cb4dfa7658b9b5b75d18063e724e201d36271da16df9571

See more details on using hashes here.

File details

Details for the file kapak-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: kapak-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for kapak-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08369cedf5ad66f6f6e4336ff6225220a570d41ef20e116bdf90baa749379795
MD5 15c60e598a70bf268f4f1c222f510741
BLAKE2b-256 96121516bc89bfa99558c3cbc639b180567c48b4d1c6faa7acadfec91cbd9725

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page