# Path: eulfedora/util.py
# def force_text(s, encoding='utf-8'):
#     if six.PY3:
#         if isinstance(s, bytes):
#             s = six.text_type(s, encoding)
#         else:
#             s = six.text_type(s)
#     else:
#         s = six.text_type(bytes(s), encoding)
# 
#     return s


from Crypto.Cipher import Blowfish as EncryptionAlgorithm
    from django.conf import settings
from eulfedora.util import force_text
import hashlib
import logging
import six
        KEY_MIN_CHARS = 32/8
        KEY_MAX_CHARS = 448/8
        if KEY_MIN_CHARS <= len(settings.SECRET_KEY) <= KEY_MAX_CHARS:
            ENCRYPTION_KEY = settings.SECRET_KEY
        else:
            ENCRYPTION_KEY = hashlib.sha224(settings.SECRET_KEY).hexdigest()
            message = '''Django secret key (current length of %d) requires hashing for use as encryption key
            (to avoid hashing, should be %d-%d characters)''' % \
            (len(settings.SECRET_KEY), KEY_MIN_CHARS, KEY_MAX_CHARS)
            logger.warn(message)
    return ENCRYPTION_KEY


def encrypt(text):
    'Encrypt a string using an encryption key based on the django SECRET_KEY'
    crypt = EncryptionAlgorithm.new(_get_encryption_key())
    return crypt.encrypt(to_blocksize(text))


def decrypt(text):
    'Decrypt a string using an encryption key based on the django SECRET_KEY'
    crypt = EncryptionAlgorithm.new(_get_encryption_key())
    return crypt.decrypt(text).rstrip(ENCRYPT_PAD_CHARACTER)


def to_blocksize(password):
    # pad the text to create a string of acceptable block size for the encryption algorithm
    width = len(password) + \
        (EncryptionAlgorithm.block_size - len(password) % EncryptionAlgorithm.block_size)
    block = password.ljust(

# Path: eulfedora/util.py
# def force_text(s, encoding='utf-8'):
#     if six.PY3:
#         if isinstance(s, bytes):
#             s = six.text_type(s, encoding)
#         else:
#             s = six.text_type(s)
#     else:
#         s = six.text_type(bytes(s), encoding)
# 
#     return s


# Path: eulfedora/cryptutil.py
from Crypto.Cipher import Blowfish as EncryptionAlgorithm
    from django.conf import settings
from eulfedora.util import force_text
import hashlib
import logging
import six

        KEY_MIN_CHARS = 32/8
        KEY_MAX_CHARS = 448/8
        if KEY_MIN_CHARS <= len(settings.SECRET_KEY) <= KEY_MAX_CHARS:
            ENCRYPTION_KEY = settings.SECRET_KEY
        else:
            ENCRYPTION_KEY = hashlib.sha224(settings.SECRET_KEY).hexdigest()
            message = '''Django secret key (current length of %d) requires hashing for use as encryption key
            (to avoid hashing, should be %d-%d characters)''' % \
            (len(settings.SECRET_KEY), KEY_MIN_CHARS, KEY_MAX_CHARS)
            logger.warn(message)
    return ENCRYPTION_KEY


def encrypt(text):
    'Encrypt a string using an encryption key based on the django SECRET_KEY'
    crypt = EncryptionAlgorithm.new(_get_encryption_key())
    return crypt.encrypt(to_blocksize(text))


def decrypt(text):
    'Decrypt a string using an encryption key based on the django SECRET_KEY'
    crypt = EncryptionAlgorithm.new(_get_encryption_key())
    return crypt.decrypt(text).rstrip(ENCRYPT_PAD_CHARACTER)


def to_blocksize(password):
    # pad the text to create a string of acceptable block size for the encryption algorithm
    width = len(password) + \
        (EncryptionAlgorithm.block_size - len(password) % EncryptionAlgorithm.block_size)
    block = password.ljust(

        width, force_text(ENCRYPT_PAD_CHARACTER) if six.PY3 else ENCRYPT_PAD_CHARACTER)