# Path: newsApp/dbhelper.py
# def decryptSecret(value, encryptionKey):
#     """
#     Helper function to decrypt a secret stored in database.
#     """
# 
#     cipherText = base64.b64decode(value)
#     aesCipher = AES.new(encryptionKey.encode('ascii'), AES.MODE_ECB)
#     decryptedBytes = aesCipher.decrypt(cipherText)
#     return decryptedBytes.decode('ascii').rstrip('{')
# 
# def encryptSecret(value, encryptionKey):
#     """
#     Helper function to encrypt a secret before storing in database.
#     """
# 
#     value = value + (16 - len(value) % 16) * '{'
#     aesCipher = AES.new(encryptionKey.encode('ascii'), AES.MODE_ECB)
#     cipherText = aesCipher.encrypt(value.encode('ascii'))
#     encryptedBytes = base64.b64encode(cipherText)
#     return encryptedBytes.decode('ascii')


import unittest
import time
from newsApp.dbhelper import decryptSecret, encryptSecret


class DbHelperTests(unittest.TestCase):

    def testEncryptDecrypt(self):
        encKey = 'kjvorn#4gjha52sg'
        value = 'testSecretValue'

        encryptedVal = encryptSecret(value, encKey)


# Path: newsApp/dbhelper.py
# def decryptSecret(value, encryptionKey):
#     """
#     Helper function to decrypt a secret stored in database.
#     """
# 
#     cipherText = base64.b64decode(value)
#     aesCipher = AES.new(encryptionKey.encode('ascii'), AES.MODE_ECB)
#     decryptedBytes = aesCipher.decrypt(cipherText)
#     return decryptedBytes.decode('ascii').rstrip('{')
# 
# def encryptSecret(value, encryptionKey):
#     """
#     Helper function to encrypt a secret before storing in database.
#     """
# 
#     value = value + (16 - len(value) % 16) * '{'
#     aesCipher = AES.new(encryptionKey.encode('ascii'), AES.MODE_ECB)
#     cipherText = aesCipher.encrypt(value.encode('ascii'))
#     encryptedBytes = base64.b64encode(cipherText)
#     return encryptedBytes.decode('ascii')


# Path: tests/dbhelper_test.py
import unittest
import time
from newsApp.dbhelper import decryptSecret, encryptSecret



class DbHelperTests(unittest.TestCase):

    def testEncryptDecrypt(self):
        encKey = 'kjvorn#4gjha52sg'
        value = 'testSecretValue'

        encryptedVal = encryptSecret(value, encKey)


        decryptedVal = decryptSecret(encryptedVal, encKey)