pyAesCrypt


NamepyAesCrypt JSON
Version 6.1.1 PyPI version JSON
download
home_pagehttps://github.com/marcobellaccini/pyAesCrypt
SummaryEncrypt and decrypt files and streams in AES Crypt format (version 2)
upload_time2023-11-11 11:14:20
maintainer
docs_urlNone
authorMarco Bellaccini
requires_python
licenseApache License 2.0
keywords aes crypt encrypt decrypt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            pyAesCrypt
===============
.. image:: https://github.com/marcobellaccini/pyaescrypt/actions/workflows/main.yml/badge.svg
    :target: https://github.com/marcobellaccini/pyAesCrypt/actions
.. image:: https://pepy.tech/badge/pyaescrypt
    :target: https://pepy.tech/project/pyaescrypt

About pyAesCrypt
--------------------------
pyAesCrypt is a Python 3 file-encryption module and script that uses AES256-CBC to encrypt/decrypt files and binary streams.

pyAesCrypt is compatible with the `AES Crypt`_ `file format`_ (version 2).

It is Free Software, released under the `Apache License, Version 2.0`_.

pyAesCrypt is brought to you by Marco Bellaccini - marco.bellaccini(at!)gmail.com.
 
IMPORTANT SECURITY NOTE: version 2 of the AES Crypt file format does not authenticate the "file size modulo 16" byte. This implies that an attacker  
with write access to the encrypted file may alter the corresponding plaintext file size by up to 15 bytes.

NOTE: there is no low-level memory management in Python, hence it is not possible to wipe memory areas were sensitive information was stored.

Module usage example
------------------------
Here is an example showing encryption and decryption of a file:

.. code:: python

    import pyAesCrypt
    password = "please-use-a-long-and-random-password"
    # encrypt
    pyAesCrypt.encryptFile("data.txt", "data.txt.aes", password)
    # decrypt
    pyAesCrypt.decryptFile("data.txt.aes", "dataout.txt", password)

**This is the most straightforward way to use pyAesCrypt, and should be preferred.**

If you need to specify a custom buffer size (default is 64KB), you can pass it as an optional argument:

.. code:: python

    import pyAesCrypt
    # custom encryption/decryption buffer size (default is 64KB)
    bufferSize = 128 * 1024
    password = "please-use-a-long-and-random-password"
    # encrypt
    pyAesCrypt.encryptFile("data.txt", "data.txt.aes", password, bufferSize)
    # decrypt
    pyAesCrypt.decryptFile("data.txt.aes", "dataout.txt", password, bufferSize)

In case you need it, you can work with binary streams too:

.. code:: python

    import pyAesCrypt
    from os import stat, remove
    # encryption/decryption buffer size - 64K
    # with stream-oriented functions, setting buffer size is mandatory
    bufferSize = 64 * 1024
    password = "please-use-a-long-and-random-password"
    
    # encrypt
    with open("data.txt", "rb") as fIn:
        with open("data.txt.aes", "wb") as fOut:
            pyAesCrypt.encryptStream(fIn, fOut, password, bufferSize)
    
    # decrypt
    with open("data.txt.aes", "rb") as fIn:
        try:
            with open("dataout.txt", "wb") as fOut:
                # decrypt file stream
                pyAesCrypt.decryptStream(fIn, fOut, password, bufferSize)
        except ValueError:
            # remove output file on error
            remove("dataout.txt")

you can also perform in-memory encryption/decryption (using BytesIO):

.. code:: python

    import pyAesCrypt
    import io
    
    bufferSize = 64 * 1024
    password = "please-use-a-long-and-random-password"
    
    # binary data to be encrypted
    pbdata = b"This is binary plaintext \x00\x01"
    
    # input plaintext binary stream
    fIn = io.BytesIO(pbdata)
    
    # initialize ciphertext binary stream
    fCiph = io.BytesIO()
    
    # initialize decrypted binary stream
    fDec = io.BytesIO()
    
    # encrypt stream
    pyAesCrypt.encryptStream(fIn, fCiph, password, bufferSize)
    
    # print encrypted data
    print("This is the ciphertext:\n" + str(fCiph.getvalue()))
    
    # go back to the start of the ciphertext stream
    fCiph.seek(0)
    
    # decrypt stream
    pyAesCrypt.decryptStream(fCiph, fDec, password, bufferSize)
    
    # print decrypted data
    print("Decrypted data:\n" + str(fDec.getvalue()))



Script usage examples
------------------------
Encrypt file test.txt in test.txt.aes:

	pyAesCrypt -e test.txt

Decrypt file test.txt.aes in test.txt:

	pyAesCrypt -d test.txt.aes
	
Encrypt file test.txt in test2.txt.aes:

	pyAesCrypt -e test.txt -o test2.txt.aes

Decrypt file test.txt.aes in test2.txt:

	pyAesCrypt -d test.txt.aes -o test2.txt

FAQs
------------------------
- *Is pyAesCrypt malware?*

  **NO!** Of course it isn't!

  Nevertheless, being a module, it can be used by any other software, including malware.
  
  In fact, it has been reported that it is used as crypto library by some ransomware.

.. _AES Crypt: https://www.aescrypt.com
.. _file format: https://www.aescrypt.com/aes_file_format.html
.. _Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/marcobellaccini/pyAesCrypt",
    "name": "pyAesCrypt",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "AES Crypt encrypt decrypt",
    "author": "Marco Bellaccini",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/29/17/59bdb5f36bcf376d11ea16f5d1b4113b783a3ff0b201ff34cec91f836bde/pyAesCrypt-6.1.1.tar.gz",
    "platform": null,
    "description": "pyAesCrypt\n===============\n.. image:: https://github.com/marcobellaccini/pyaescrypt/actions/workflows/main.yml/badge.svg\n    :target: https://github.com/marcobellaccini/pyAesCrypt/actions\n.. image:: https://pepy.tech/badge/pyaescrypt\n    :target: https://pepy.tech/project/pyaescrypt\n\nAbout pyAesCrypt\n--------------------------\npyAesCrypt is a Python 3 file-encryption module and script that uses AES256-CBC to encrypt/decrypt files and binary streams.\n\npyAesCrypt is compatible with the `AES Crypt`_ `file format`_ (version 2).\n\nIt is Free Software, released under the `Apache License, Version 2.0`_.\n\npyAesCrypt is brought to you by Marco Bellaccini - marco.bellaccini(at!)gmail.com.\n \nIMPORTANT SECURITY NOTE: version 2 of the AES Crypt file format does not authenticate the \"file size modulo 16\" byte. This implies that an attacker  \nwith write access to the encrypted file may alter the corresponding plaintext file size by up to 15 bytes.\n\nNOTE: there is no low-level memory management in Python, hence it is not possible to wipe memory areas were sensitive information was stored.\n\nModule usage example\n------------------------\nHere is an example showing encryption and decryption of a file:\n\n.. code:: python\n\n    import pyAesCrypt\n    password = \"please-use-a-long-and-random-password\"\n    # encrypt\n    pyAesCrypt.encryptFile(\"data.txt\", \"data.txt.aes\", password)\n    # decrypt\n    pyAesCrypt.decryptFile(\"data.txt.aes\", \"dataout.txt\", password)\n\n**This is the most straightforward way to use pyAesCrypt, and should be preferred.**\n\nIf you need to specify a custom buffer size (default is 64KB), you can pass it as an optional argument:\n\n.. code:: python\n\n    import pyAesCrypt\n    # custom encryption/decryption buffer size (default is 64KB)\n    bufferSize = 128 * 1024\n    password = \"please-use-a-long-and-random-password\"\n    # encrypt\n    pyAesCrypt.encryptFile(\"data.txt\", \"data.txt.aes\", password, bufferSize)\n    # decrypt\n    pyAesCrypt.decryptFile(\"data.txt.aes\", \"dataout.txt\", password, bufferSize)\n\nIn case you need it, you can work with binary streams too:\n\n.. code:: python\n\n    import pyAesCrypt\n    from os import stat, remove\n    # encryption/decryption buffer size - 64K\n    # with stream-oriented functions, setting buffer size is mandatory\n    bufferSize = 64 * 1024\n    password = \"please-use-a-long-and-random-password\"\n    \n    # encrypt\n    with open(\"data.txt\", \"rb\") as fIn:\n        with open(\"data.txt.aes\", \"wb\") as fOut:\n            pyAesCrypt.encryptStream(fIn, fOut, password, bufferSize)\n    \n    # decrypt\n    with open(\"data.txt.aes\", \"rb\") as fIn:\n        try:\n            with open(\"dataout.txt\", \"wb\") as fOut:\n                # decrypt file stream\n                pyAesCrypt.decryptStream(fIn, fOut, password, bufferSize)\n        except ValueError:\n            # remove output file on error\n            remove(\"dataout.txt\")\n\nyou can also perform in-memory encryption/decryption (using BytesIO):\n\n.. code:: python\n\n    import pyAesCrypt\n    import io\n    \n    bufferSize = 64 * 1024\n    password = \"please-use-a-long-and-random-password\"\n    \n    # binary data to be encrypted\n    pbdata = b\"This is binary plaintext \\x00\\x01\"\n    \n    # input plaintext binary stream\n    fIn = io.BytesIO(pbdata)\n    \n    # initialize ciphertext binary stream\n    fCiph = io.BytesIO()\n    \n    # initialize decrypted binary stream\n    fDec = io.BytesIO()\n    \n    # encrypt stream\n    pyAesCrypt.encryptStream(fIn, fCiph, password, bufferSize)\n    \n    # print encrypted data\n    print(\"This is the ciphertext:\\n\" + str(fCiph.getvalue()))\n    \n    # go back to the start of the ciphertext stream\n    fCiph.seek(0)\n    \n    # decrypt stream\n    pyAesCrypt.decryptStream(fCiph, fDec, password, bufferSize)\n    \n    # print decrypted data\n    print(\"Decrypted data:\\n\" + str(fDec.getvalue()))\n\n\n\nScript usage examples\n------------------------\nEncrypt file test.txt in test.txt.aes:\n\n\tpyAesCrypt -e test.txt\n\nDecrypt file test.txt.aes in test.txt:\n\n\tpyAesCrypt -d test.txt.aes\n\t\nEncrypt file test.txt in test2.txt.aes:\n\n\tpyAesCrypt -e test.txt -o test2.txt.aes\n\nDecrypt file test.txt.aes in test2.txt:\n\n\tpyAesCrypt -d test.txt.aes -o test2.txt\n\nFAQs\n------------------------\n- *Is pyAesCrypt malware?*\n\n  **NO!** Of course it isn't!\n\n  Nevertheless, being a module, it can be used by any other software, including malware.\n  \n  In fact, it has been reported that it is used as crypto library by some ransomware.\n\n.. _AES Crypt: https://www.aescrypt.com\n.. _file format: https://www.aescrypt.com/aes_file_format.html\n.. _Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Encrypt and decrypt files and streams in AES Crypt format (version 2)",
    "version": "6.1.1",
    "project_urls": {
        "Homepage": "https://github.com/marcobellaccini/pyAesCrypt"
    },
    "split_keywords": [
        "aes",
        "crypt",
        "encrypt",
        "decrypt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e9b07ec8433044d6e178fb6cc5e559d8027dad72f6d6b17b56e955013413ba21",
                "md5": "88e3b075a3a0cb5890311f87ed254969",
                "sha256": "302ac75aa76d70e3e42c56c445e2581e24fabac7ae2e309deb7b8b2c6da95e39"
            },
            "downloads": -1,
            "filename": "pyAesCrypt-6.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "88e3b075a3a0cb5890311f87ed254969",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 16037,
            "upload_time": "2023-11-11T11:14:18",
            "upload_time_iso_8601": "2023-11-11T11:14:18.701804Z",
            "url": "https://files.pythonhosted.org/packages/e9/b0/7ec8433044d6e178fb6cc5e559d8027dad72f6d6b17b56e955013413ba21/pyAesCrypt-6.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "291759bdb5f36bcf376d11ea16f5d1b4113b783a3ff0b201ff34cec91f836bde",
                "md5": "303279ab48538621e4f908b8b427c6d8",
                "sha256": "6bf8f97c03ec0e42008da911ac25e523f11f160f684d5f2bc9579ce501be9eae"
            },
            "downloads": -1,
            "filename": "pyAesCrypt-6.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "303279ab48538621e4f908b8b427c6d8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14752,
            "upload_time": "2023-11-11T11:14:20",
            "upload_time_iso_8601": "2023-11-11T11:14:20.370219Z",
            "url": "https://files.pythonhosted.org/packages/29/17/59bdb5f36bcf376d11ea16f5d1b4113b783a3ff0b201ff34cec91f836bde/pyAesCrypt-6.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-11 11:14:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "marcobellaccini",
    "github_project": "pyAesCrypt",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyaescrypt"
}
        
Elapsed time: 0.13464s