Ejemplo n.º 1
0
def encrypt(encoded):
    '''
    Encrypt a k=v encoded string using AES ECB mode.
    Returns the ciphertext.
    '''
    global PROFILE_SECRET_KEY
    if not PROFILE_SECRET_KEY:
        PROFILE_SECRET_KEY = crypto.random_AES_key()

    plain = crypto.str_to_bytes(encoded)
    plain = crypto.plaintext_pad_PKCS7(plain)
    return crypto.encrypt_AES_ECB(plain, PROFILE_SECRET_KEY)
Ejemplo n.º 2
0
def decrypt(cipher):
    '''
    Decrypt a ciphertext and parse it to produce a profile..
    '''
    global PROFILE_SECRET_KEY
    if not PROFILE_SECRET_KEY:
        PROFILE_SECRET_KEY = crypto.random_AES_key()

    plain = crypto.decrypt_AES_ECB(cipher, PROFILE_SECRET_KEY)
    # Crudely remove any padding
    plain=plain.decode()
    plain = ''.join(filter(string.printable.__contains__, str(plain)))

    print('About to parse {0}'.format(plain))

    return parse(plain)