Skip to main content

Python library used to encrypt and decrypt strings in the simplest possible way, while also being incredibly secure.

Project description

gKey

Python library used to encrypt and decrypt strings in the simplest possible way, while also being incredibly secure.

Requirements

  • Python 3 or later.
  • Several Python packages:
    • pycryptodome, to help encrypt and decrypt messages.

Installation

Install some Python utilities along with some libraries and other stuff:

pip install pycryptodome gkey

Basic usage

Encrypting a message:

>>> import gkey
>>> myEncryptedMessage = gkey.encrypt("I like trains", "password123")
>>> print(myEncryptedMessage)
M+Wykmlub0z7FhEdmA==*PvAbXRNx0SiSDHHxLsKZ5w==*ihQM/fdkgrX3G+yOItyAUQ==*QFNDmuUP1ysgo01/P2MNpg==

The first parameter is the string you want to encrypt. The second parameter is the password, which will be used for decrypting the string.

Decrypting a message"

>>> import gkey
>>> myDecryptedMessage = gkey.decrypt("M+Wykmlub0z7FhEdmA==*PvAbXRNx0SiSDHHxLsKZ5w==*ihQM/fdkgrX3G+yOItyAUQ==*QFNDmuUP1ysgo01/P2MNpg==", "password123")
>>> print(myDecryptedMessage)
I like trains

The first parameter is the encrypted string and the second parameter is the password. If the password is incorrect, decrypt function will return False.

Example

Here, we will be creating a simple "trial product key". This is useful if you have software that you would like people to use temporarily. In this example, we will be letting the user use the product for 2 hours. The password we will be using is gKey is amazing.

Code on the server side:

import gkey
import time
hours = 2
messageToEncrypt = str(time.time() + hours * 60 * 60)
## Hours * 60 * 60 is necessary because we need to turn the hours into seconds, since the timestamp is in seconds.
gkey.encrypt(messageToEncrypt, "gKey is amazing")

Code on the client side:

import gkey
import time
import sys
#Function to verify that the key is valid:
def check_valid(key):
    message = gkey.decrypt(key, 'gkey is amazing')
    if message == False:
        #The key is incorrect!
        return False
    if float(message) >= time.time():
        return True
    else:
        #The key has expired!
        return False
userKeyInput = input("Please enter your product key.")
keyChecked = check_valid(userKeyInput)
if keyChecked == True:
    print("You are good to go!")
if keyChecked == False:
    print("You have either entered an invalid key or your time has expired. Sorry!")
    sys.exit()

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

gKey-0.0.2.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gKey-0.0.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file gKey-0.0.2.tar.gz.

File metadata

  • Download URL: gKey-0.0.2.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.7

File hashes

Hashes for gKey-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8b163827555611bda2a5608376fdcb6d51c16f42a8ffdcbc310a2ab9a871174c
MD5 2cec624e528850c198c1cfe1dfc569cc
BLAKE2b-256 6372717e9bd149bf0999d43a691feaf4e51e4785b66475f2910652603246dd92

See more details on using hashes here.

File details

Details for the file gKey-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: gKey-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.7

File hashes

Hashes for gKey-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f11988c4a91cd74ba346ce1d9ecb26b04f733cde29af9a5cd1f3865278f3dd47
MD5 9ccaf3eab337c4dcdf5769ee5c433a30
BLAKE2b-256 cab29a458edecc6d2c405bf7135e720828fe8b1881014c83812bff7b7899938d

See more details on using hashes here.

Supported by

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