keycipher
is a Python utility package for encrypting and decrypting text using AES-GCM with a secret key. It provides simple functions to handle secure encryption and decryption.
To install the package, use pip:
pip install keycipher
Here’s a brief guide on how to use the keycipher
package.
from keycipher import encrypt_data, decrypt_data
To encrypt a piece of text, use the encrypt_data
function. You need to provide the plaintext and a key string.
from keycipher import encrypt_data
key_string = 'your-secret-key' # Replace with your key
plain_text = 'This is a secret message' # Replace with your text
encrypted_data = encrypt_data(plain_text, key_string)
print('Encrypted Data:', encrypted_data)
To decrypt data, use the decrypt_data
function. You need to provide the encrypted data and the same key string used for encryption.
from keycipher import decrypt_data
encrypted_data = {
'iv': '...your IV...',
'cipherText': '...your cipherText...',
'tag': '...your tag...'
} # Replace with your generated encryption object
key_string = 'your-secret-key' # Replace with your key
decrypted_text = decrypt_data(encrypted_data, key_string)
print('Decrypted Text:', decrypted_text)
Encrypts the given plaintext using the provided key string.
-
Arguments:
plain_text
(str): The text to be encrypted.key_string
(str): The key used for encryption.
-
Returns: A dictionary containing
iv
,cipherText
, andtag
.
Decrypts the given encrypted data using the provided key string.
-
Arguments:
encrypted_data
(dict): The encrypted data object, which includesiv
,cipherText
, andtag
.key_string
(str): The key used for decryption.
-
Returns: The decrypted text.
Here’s a complete example showing both encryption and decryption:
from keycipher import encrypt_data, decrypt_data
# Encryption
key_string = 'your-secret-key'
plain_text = 'This is a secret message'
encrypted_data = encrypt_data(plain_text, key_string)
print('Encrypted Data:', encrypted_data)
# Decryption
decrypted_text = decrypt_data(encrypted_data, key_string)
print('Decrypted Text:', decrypted_text)
keycipher
is created by Parth Dudhatra (imParth), a passionate software engineer, developer advocate, and content creator known for his contributions to the tech community. He is passionate about frontend development, Python programming, open-source software, and sharing knowledge with others.
Parth is active on various social media platforms, where he shares insights, tutorials, and tips related to programming, web development, and software engineering. Parth's dedication to sharing his expertise and fostering a supportive environment for developers has earned him recognition and respect within the tech community. Connect with Parth Dudhatra on social media:
If you have any questions, feedback, or suggestions, feel free to reach out to me on any platform!
This project is licensed under the ISC License.
Contributions are welcome! Please open an issue or submit a pull request on the GitHub repository.
If you encounter any issues, please report them on the issues page.