Package: pycryptex
PyCryptexThis project can be used as:CLI application for encryption and decryptiona package to import in your personal project to create an encryption/decryption appFor the CLI functionality it usesclickpackage and for the encryption the amazingpycryptodomepackage.Install applicationTo usepycryptexyou need to have python3 and pip3 installed. Depending on you platform the procedure to install python can change.
Try this on your terminal:python3-VIf you do not get an answer the best place to to start is looking into the official documentationhere.Then, when you have at least Python >= 3.6 and pip3 installed, simply type:python3-mpipinstallpycryptexIf you are on linux you could have this warning:WARNING: The script pycryptex is installed in '/home/<YOUR-HOME>/.local/bin' which is not on PATH.It means that if you typepycryptexyou get a not found error.
To solve, simply add the path to your PATH, for example, edit .bashrc in your $HOME folder as (suppose your HOME == vagrant):# Add local python bin script to my PATH:
export PATH=$PATH:/home/vagrant/.local/binif you do not use BASH as a shell, search the same src file for your shell and edit in a similar way.
Then execute, in case of BASH:source $HOME/.bashrc
# and then type
pycryptexIt should work now and for all the future updates!Fast startIf you want encrypt and decrypt files and folders easily and you do not want spend time to create your own encryption keys, you can let
PyCryptex do the job for you (to use your own keys or understanding better the behaviour of the application refers to the rest of the documentation):pycryptexcreate-keysanswer 'yes' and decide if protect the private key with a password (it's your security choice).
PyCryptex will create the standard key in your$HOME/.pycryptexfolder.IMPORTANT: you will use your public key (pycryptex_key.pub) for encrypt and you private key (pycryptex_key) for decrypt. Do not leave the keys in the same place, secure you private key as best as you can, as you do with your private HOME keys ;-)!At this point you can simply encrypt a file or a folder using:pycryptexencrypt<FILE-OR-FOLDER>everytime you need to know the options behind a command digit:pycryptex<command>--helpTo decrypt a file or a folder type:pycryptexdecrypt<FILE-OR-FOLDER>That's it for the PyCryptex in anutshell. Go ahead with the lecture to figure out how to make the most of the application.Decryption with a pagerPager option behaviour is changed in version0.5.0. Now it is possible to usedecryptionalso for reading a file without saving the clear file on the system (if it is not needed).
Actually the pager is enabled only for the commanddecryptand not for the commanddecrypt-aes.
So, for example if you decrypt without option:pycryptexdecrypt<FILE-OR-FOLDER>PyCryptex will save the decrypted file on the file system, instead if you type:pycryptexdecrypt<FILE-OR-FOLDER>--pagerPyCryptex will decrypt the file in memory and redirect it on the standard input of the pager set in your configuration file.
Starting from0.5.0version is also changed the default pager in favour of 'less' instead of 'vim'.
You can change it to use your favourite pager (simply create the configuration filepycryptex create-configthen edit it),
some examples are:code -to use Visual Studio Code (to enable the commandcodesee the Microsoft site)sublime -to use with sublime (in case you do not have it on the executable in PATH, see on the official documentation to solve the issue)vim -to use vimnano -to use nano (starting from version 2.2)Happy Encryption!!!Using applicationYou can get help with:pycryptex--helpPyCryptex encryption works with symmetric or asymmetric algorithms based on the arguments passed.
To the standard encryption/decryptionpycryptexuses RSA keys pair. In particular, it encrypts using the public key of the user and decrypts
using the private key. For better performancepycryptexbehind the scene uses the AES algorithm.
The RSA keys are used to encrypt and decrypt the random key generated and stored as header to the file.
In this way the performance are definitely better on a large file (a 256 bit AES random key is used).The default keys name:pycryptex_key: for the private keypycryptex_key.pub: for the public key
The folder wherepycryptexsearches for the key is your $HOME/.pycryptex. If you prefer to use your own
keys you can pass them directly as an argument to the encrypt and decrypt method.An alternative, starting from version 0.4.0, could be save the path of the keys in the pycryptex confi file.PyCryptex determines the RSA keys to usefor theencryptanddecryptmethods, follow these rules:if the option --privkey or --pubkey is specified, it loads the corresponding fileif no option key is specified:if is present privkey or pubkey field in$HOME/.pycryptex/pycryptex.tomlit loads the corresponding fileloads pycryptex_key as private key and pycryptex_key.pub located in$HOME/.pycryptexdirectoryThese rules are not valid when you useencrypt-aesanddecrypt-aescommands that always ask for a console password.Configuration filePyCryptex reads a configuration file located in your $HOME/.pycryptex folder namedpycryptex.toml.
The file has the following syntax (reported are the default file):[config]# path to the pager application where to see decrypted filepager="vim"# default private key for RSA decryptionprivate-key=""# default public key for RSA encryptionpublic-key=""# (default false) true/false to secure delete files (if activated deletion of files becomes slower)secure-deletion=false# number of passes for secure deletion. Means how many times PyCryptex write random data into the file.# greater is the number you adopt, major security you introduce but deletion becomes slower.secure-deletion-passes=1Secure file deletionStarting from0.5.0it is possible to set the config keysecure-deletion= true. Doing this, the clear file/s,
after the encryption, will be removed safely. It's possible to configure how many passes to run to mix up the file content
before deleting it.List of all commandsTo an explanation of all the option of a specific command take a look directly at:pycryptexencrypt--helpFollow the list of commands:encrypt: to encrypt a single file or a folder (including sub folders).decrypt: to decrypt a single file a single file or a folder (including sub folders).create-keys: to create a public key and private key pair.create-config: to create the default config file under $HOME/.pycryptex/pycryptex.tomlshow-config: to show the configuration file if present into the $HOME/.pycryptex folderencrypt-aes: to encrypt a single file or a folder (including sub folders) using AES algorithm.decrypt-aes: to decrypt a single file a single file or a folder (including sub folders) using AES algorithm.Some examplesSome basic example usages are:# to encrypt passing a keypycryptexencrypt--pubkeytest/id_rsa.pubtest/secrets.txt# to encrypt using the pycryptex_key.pub in $HOME/.pycryptex folderpycryptexencrypttest/secret.txt# to encrypt using the pycryptex_key.pub in $HOME/.pycryptex folder maintaining the original filepycryptexencrypttest/secret.txt--keep# decrypt the filepycryptex--verbosedecrypt--privkeytest/id_rsatest/secrets.txt.pycpx# decrypt using your own private key and open the pagerpycryptex--verbosedecrypt--privkeytest/id_rsa-ptest/secrets.txt.pycpx# decrypt and open the pager (loading keys from $HOME/.pycryptex)pycryptexdecrypt-ptest/secrets.txt.pycpx# to create private/public key pairspycryptexcreate-keysTo combine decrypt + read and modify a file + encrypt again you can use something as:pycryptexdecrypt--privkey<YOUR-PATH-TO-PRIVATE-KEY><FILE.pycypx>\&&vim<FILE>&&\pycryptexencrypt--pubkey<YOUR-PATH-TO-PUBLIC-KEY><FILE>By this way, you can change the clear content also using the right pager, as vim for example.
In case your keys are in yourpycryptexHOME folder or set into thepycryptex.tomlfile, you can omit to pass them.
If you need only read an encrypted file content use simple the --pager option as described before.Shell auto completion for pycryptexPyCryptex commands, options and arguments can be added to your favourite shell for the auto completion.
After you have installed the application follow the instructions choosing the shell you have.bashconfigurationIf your favourite shell isbashthen type:cd<YOUR-FOLDER># type this command_PYCRYPTEX_COMPLETE=source_bashpycryptex>pycryptex.shnow you that have the filepycryptex.shopen you $HOME/.bashrc file and add this content:vim$HOME/.bashrcsource/PATH-TO-PYCRYPTEX-SCRIPT/pycryptex.shzshconfigurationIf your favourite shell iszshthen type:cd<YOUR-FOLDER># type this command_PYCRYPTEX_COMPLETE=source_zshpycryptex>pycryptex.shnow you that have the filepycryptex.shopen you $HOME/.zshrc file and add this content:vim$HOME/.zshrcsource/PATH-TO-PYCRYPTEX-SCRIPT/pycryptex.shfishconfigurationIf your favourite shell isfishthen type:_PYCRYPTEX_COMPLETE=source_fishpycryptex>~/.config/fish/completions/pycryptex-complete.fishConfiguration for developersIf you want to contribute to that project, after cloning the repo type:gitclonehttps://github.com/mas2020-python/pycryptex.gitcdpycryptex
python3-mvenvvenvsourcevenv/bin/activate
python3-mpipinstall--upgradepip
pipinstall--upgradesetuptools
pipinstall-rrequirements.txt
python3-mpipinstallpytestwheeltwine# (optional) to test typepython3-mCrypto.SelfTestIf you need to create a new key pair you can use ssh-keygen. In such case type:ssh-keygen-trsa-b4096-C"<your-user>@<your-domain>"To install the executable package type:pip3install--editable.To install from PyPi test (other dependencies packages from official PyPi) type:pip3install-ihttps://test.pypi.org/simple/--extra-index-urlhttps://pypi.org/simplepycryptex==<VERSION>To test the application type:pytestTo deploy on PyPi test:python3setup.pycheck
python3setup.pybdist_wheelsdist
twineuploaddist/*--repositorytestpypiYou need to have the credentials or token from the owner of the project on PyPi.