PK ! ]m m cred_encryption/__init__.py__version__ = '0.1.0'
from cred_encryption.encryption import application
def run():
application.run()
PK ! e2 2 cred_encryption/encryption.pyimport os
import base64
from cryptography.fernet import Fernet
from cleo import Application, Command as BaseCommand
from typing import Optional
class Command(BaseCommand):
@property
def secret_key(self) -> Optional[str]:
try:
return os.environ['OLAS_SECURITYCONFIG_HASH'][:32]
except KeyError:
self.line('Unable to perform encrypt/decrypt operations because the environmental variable '
'`OLAS_SECURITYCONFIG_HASH` is not set and the `key` argument was not provided')
return None
class EncryptCommand(Command):
"""
Encrypts a given value
encrypt
{value : The value to encrypt}
{key? : The key to encrypt against}
"""
def handle(self) -> None:
value = self.argument('value')
key = self.argument('key')
if key:
SECRET_KEY = key[:32]
else:
SECRET_KEY = self.secret_key
if SECRET_KEY:
key = base64.urlsafe_b64encode(bytes(SECRET_KEY.encode()))
cipher_suite = Fernet(key)
plain_text = cipher_suite.encrypt(value.encode())
self.line('ENCRYPTED VALUE:')
self.line(f'{plain_text.decode()}')
class DecryptCommand(Command):
"""
Decrypts a given value
decrypt
{value : The value to encrypt}
{key? : The key to encrypt against}
"""
def handle(self) -> None:
cipher_text = self.argument('value')
key = self.argument('key')
if key:
SECRET_KEY = key[:32]
else:
SECRET_KEY = self.secret_key
if SECRET_KEY:
key = base64.urlsafe_b64encode(bytes(SECRET_KEY.encode()))
cipher_suite = Fernet(key)
plain_text = cipher_suite.decrypt(cipher_text.encode())
self.line('DECRYPTED VALUE:')
self.line(f'{plain_text.decode()}')
application = Application()
application.add(DecryptCommand())
application.add(EncryptCommand())
application.run()
PK !Hv+ 2 0 cred_encryption-0.3.0.dist-info/entry_points.txtN+I/N.,()JK.,(ϳM.JMGJ PK !HڽT U % cred_encryption-0.3.0.dist-info/WHEEL
A
н#Z;/"d&F[xzw@Zpy3Fv]\fi4WZ^EgM_-]#0(q7PK !H\ ( cred_encryption-0.3.0.dist-info/METADATAAK@+b"(AbQC2&lM,QSo˛74`W`}Tr]2U~A Q9);2=y)BlI]#܍C9כm[ECm+h}C P:ڊN=hO0UZmZ[={5szx:d\g;yM:z2H.A"ƂY PK !HA1 &